Passed
Push — issue#777 ( da3d73...d2ae13 )
by Guilherme
05:16
created

ClientMetadata::getClientSecret()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 3.1406

Importance

Changes 0
Metric Value
cc 3
eloc 3
nc 2
nop 0
dl 0
loc 7
ccs 3
cts 4
cp 0.75
crap 3.1406
rs 9.4285
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of the login-cidadao project or it's bundles.
4
 *
5
 * (c) Guilherme Donato <guilhermednt on github>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace LoginCidadao\OpenIDBundle\Entity;
12
13
use LoginCidadao\CoreBundle\Model\PersonInterface;
14
use LoginCidadao\OAuthBundle\Model\ClientInterface;
15
use LoginCidadao\OAuthBundle\Model\OrganizationInterface;
16
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
17
use LoginCidadao\OpenIDBundle\Validator\Constraints\SectorIdentifierUri;
18
use Symfony\Component\Validator\Constraints as Assert;
19
use LoginCidadao\OAuthBundle\Entity\Client;
20
use JMS\Serializer\Annotation as JMS;
21
use Doctrine\ORM\Mapping as ORM;
22
23
/**
24
 * @ORM\Entity(repositoryClass="LoginCidadao\OpenIDBundle\Entity\ClientMetadataRepository")
25
 * @UniqueEntity("client")
26
 * @UniqueEntity("client_name")
27
 * @ORM\HasLifecycleCallbacks
28
 * @ORM\Table(name="client_metadata")
29
 * @JMS\ExclusionPolicy("all")
30
 * @SectorIdentifierUri
31
 */
32
class ClientMetadata
33
{
34
    /**
35
     * @ORM\Id
36
     * @ORM\Column(type="integer")
37
     * @ORM\GeneratedValue(strategy="AUTO")
38
     */
39
    private $id;
40
    private $client_id;
41
    private $client_secret;
42
43
    /**
44
     * @var ClientInterface
45
     * @ORM\OneToOne(targetEntity="LoginCidadao\OAuthBundle\Entity\Client", inversedBy="metadata", cascade={"persist"})
46
     * @ORM\JoinColumn(name="client_id", referencedColumnName="id")
47
     */
48
    private $client;
49
50
    /**
51
     * @var string[]
52
     *
53
     * @JMS\Expose
54
     * @JMS\Groups({"client_metadata"})
55
     * @Assert\All({
56
     *      @Assert\Type(type="string"),
57
     *      @Assert\NotBlank,
58
     *      @Assert\Url(checkDNS = false)
59
     * })
60
     * @ORM\Column(name="redirect_uris", type="json_array", nullable=false)
61
     */
62
    private $redirect_uris;
63
64
    /**
65
     * @JMS\Expose
66
     * @JMS\Groups({"client_metadata"})
67
     * @Assert\All({
68
     *      @Assert\Type("string")
69
     * })
70
     * @ORM\Column(name="response_types", type="simple_array", nullable=false)
71
     */
72
    private $response_types = ['code'];
73
74
    /**
75
     * @JMS\Expose
76
     * @JMS\Groups({"client_metadata"})
77
     * @Assert\All({
78
     *      @Assert\Type("string")
79
     * })
80
     * @ORM\Column(type="simple_array", nullable=false)
81
     */
82
    private $grant_types = ['authorization_code'];
83
84
    /**
85
     * @JMS\Expose
86
     * @JMS\Groups({"client_metadata"})
87
     * @Assert\Type(type="string")
88
     * @ORM\Column(name="application_type", type="string", length=100, nullable=false)
89
     */
90
    private $application_type = 'web';
91
92
    /**
93
     * @JMS\Expose
94
     * @JMS\Groups({"client_metadata"})
95
     * @Assert\All({
96
     *      @Assert\Type("string")
97
     * })
98
     * @ORM\Column(type="simple_array", nullable=true)
99
     */
100
    private $contacts;
101
102
    /**
103
     * @JMS\Expose
104
     * @JMS\Groups({"client_metadata"})
105
     * @Assert\Type(type="string")
106
     * @ORM\Column(type="string", nullable=true)
107
     */
108
    private $client_name;
109
110
    /**
111
     * @JMS\Expose
112
     * @JMS\Groups({"client_metadata"})
113
     * @Assert\Type(type="string")
114
     * @Assert\Url(checkDNS = false)
115
     * @ORM\Column(type="string", length=2000, nullable=true)
116
     */
117
    private $logo_uri;
118
119
    /**
120
     * @JMS\Expose
121
     * @JMS\Groups({"client_metadata"})
122
     * @Assert\Type(type="string")
123
     * @Assert\Url(checkDNS = false)
124
     * @ORM\Column(type="string", length=2000, nullable=true)
125
     */
126
    private $client_uri;
127
128
    /**
129
     * @JMS\Expose
130
     * @JMS\Groups({"client_metadata"})
131
     * @Assert\Type(type="string")
132
     * @Assert\Url(checkDNS = false)
133
     * @ORM\Column(type="string", length=2000, nullable=true)
134
     */
135
    private $policy_uri;
136
137
    /**
138
     * @JMS\Expose
139
     * @JMS\Groups({"client_metadata"})
140
     * @Assert\Url(checkDNS = false)
141
     * @Assert\Type(type="string")
142
     * @ORM\Column(type="string", length=2000, nullable=true)
143
     */
144
    private $tos_uri;
145
146
    /**
147
     * @JMS\Expose
148
     * @JMS\Groups({"client_metadata"})
149
     * @Assert\Url(checkDNS = false)
150
     * @Assert\Type(type="string")
151
     * @ORM\Column(type="string", length=2000, nullable=true)
152
     */
153
    private $jwks_uri;
154
155
    /**
156
     * @JMS\Expose
157
     * @JMS\Groups({"client_metadata"})
158
     * @Assert\Type(type="string")
159
     * @ORM\Column(type="text", nullable=true)
160
     */
161
    private $jwks;
162
163
    /**
164
     * @JMS\Expose
165
     * @JMS\Groups({"client_metadata"})
166
     * @Assert\Url(checkDNS = false, protocols = {"http", "https"})
167
     * @Assert\Type(type="string")
168
     * @ORM\Column(type="string", length=2000, nullable=true)
169
     */
170
    private $sector_identifier_uri;
171
172
    /**
173
     * @JMS\Expose
174
     * @JMS\Groups({"client_metadata"})
175
     * @Assert\Type(type="string")
176
     * @ORM\Column(type="string", length=20, nullable=false, options={"default" : "pairwise"})
177
     */
178
    private $subject_type = 'pairwise';
179
180
    /**
181
     * @JMS\Expose
182
     * @JMS\Groups({"client_metadata"})
183
     * @Assert\Type(type="string")
184
     * @ORM\Column(type="string", length=50, nullable=true)
185
     */
186
    private $id_token_signed_response_alg;
187
188
    /**
189
     * @JMS\Expose
190
     * @JMS\Groups({"client_metadata"})
191
     * @Assert\Type(type="string")
192
     * @ORM\Column(type="string", length=50, nullable=true)
193
     */
194
    private $id_token_encrypted_response_alg;
195
196
    /**
197
     * @JMS\Expose
198
     * @JMS\Groups({"client_metadata"})
199
     * @Assert\Type(type="string")
200
     * @ORM\Column(type="string", length=50, nullable=true)
201
     */
202
    private $id_token_encrypted_response_enc;
203
204
    /**
205
     * @JMS\Expose
206
     * @JMS\Groups({"client_metadata"})
207
     * @Assert\Type(type="string")
208
     * @ORM\Column(type="string", length=50, nullable=true)
209
     */
210
    private $userinfo_signed_response_alg;
211
212
    /**
213
     * @JMS\Expose
214
     * @JMS\Groups({"client_metadata"})
215
     * @Assert\Type(type="string")
216
     * @ORM\Column(type="string", length=50, nullable=true)
217
     */
218
    private $userinfo_encrypted_response_alg;
219
220
    /**
221
     * @JMS\Expose
222
     * @JMS\Groups({"client_metadata"})
223
     * @Assert\Type(type="string")
224
     * @ORM\Column(type="string", length=50, nullable=true)
225
     */
226
    private $userinfo_encrypted_response_enc;
227
228
    /**
229
     * @JMS\Expose
230
     * @JMS\Groups({"client_metadata"})
231
     * @Assert\Type(type="string")
232
     * @ORM\Column(type="string", length=50, nullable=true)
233
     */
234
    private $request_object_signing_alg;
235
236
    /**
237
     * @JMS\Expose
238
     * @JMS\Groups({"client_metadata"})
239
     * @Assert\Type(type="string")
240
     * @ORM\Column(type="string", length=50, nullable=true)
241
     */
242
    private $request_object_encryption_alg;
243
244
    /**
245
     * @JMS\Expose
246
     * @JMS\Groups({"client_metadata"})
247
     * @Assert\Type(type="string")
248
     * @ORM\Column(type="string", length=50, nullable=true)
249
     */
250
    private $request_object_encryption_enc;
251
252
    /**
253
     * @JMS\Expose
254
     * @JMS\Groups({"client_metadata"})
255
     * @Assert\Type(type="string")
256
     * @ORM\Column(type="string", length=50, nullable=true)
257
     */
258
    private $token_endpoint_auth_method;
259
260
    /**
261
     * @JMS\Expose
262
     * @JMS\Groups({"client_metadata"})
263
     * @Assert\Type(type="string")
264
     * @ORM\Column(type="string", length=50, nullable=true)
265
     */
266
    private $token_endpoint_auth_signing_alg;
267
268
    /**
269
     * @JMS\Expose
270
     * @JMS\Groups({"client_metadata"})
271
     * @Assert\Type(type="integer")
272
     * @ORM\Column(type="integer", nullable=true)
273
     */
274
    private $default_max_age;
275
276
    /**
277
     * @JMS\Expose
278
     * @JMS\Groups({"client_metadata"})
279
     * @Assert\Type(type="boolean")
280
     */
281
    private $require_auth_time = false;
282
283
    /**
284
     * @JMS\Expose
285
     * @JMS\Groups({"client_metadata"})
286
     * @Assert\Type(type="array")
287
     * @ORM\Column(type="simple_array", nullable=true)
288
     */
289
    private $default_acr_values;
290
291
    /**
292
     * @JMS\Expose
293
     * @JMS\Groups({"client_metadata"})
294
     * @Assert\Url(checkDNS = false)
295
     * @Assert\Type(type="string")
296
     * @ORM\Column(type="string", length=2000, nullable=true)
297
     */
298
    private $initiate_login_uri;
299
300
    /**
301
     * @JMS\Expose
302
     * @JMS\Groups({"client_metadata"})
303
     * @Assert\All({
304
     *      @Assert\Type("string"),
305
     *      @Assert\Url(checkDNS = false)
306
     * })
307
     * @ORM\Column(type="simple_array", nullable=true)
308
     */
309
    private $request_uris;
310
311
    /**
312
     * @JMS\Expose
313
     * @JMS\Groups({"client_metadata"})
314
     * @Assert\Type(type="string")
315
     * @ORM\Column(type="string", nullable=true)
316
     */
317
    private $registration_access_token;
318
319
    /**
320
     * @var OrganizationInterface
321
     * @ORM\ManyToOne(targetEntity="LoginCidadao\OAuthBundle\Model\OrganizationInterface", inversedBy="clients")
322
     * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL")
323
     */
324
    private $organization;
325
326
    /**
327
     * @JMS\Expose
328
     * @JMS\Groups({"client_metadata"})
329
     * @Assert\All({
330
     *      @Assert\Type("string"),
331
     *      @Assert\Url(checkDNS = false)
332
     * })
333
     * @ORM\Column(type="simple_array", nullable=true)
334
     */
335
    private $post_logout_redirect_uris;
336
337 25
    public function __construct()
338
    {
339 25
        $this->response_types = ['code'];
0 ignored issues
show
Documentation Bug introduced by
It seems like array('code') of type array<integer,string> is incompatible with the declared type string of property $response_types.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
340 25
        $this->grant_types = ['authorization_code'];
0 ignored issues
show
Documentation Bug introduced by
It seems like array('authorization_code') of type array<integer,string> is incompatible with the declared type string of property $grant_types.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
341 25
        $this->application_type = 'web';
342 25
        $this->require_auth_time = false;
343 25
        $this->subject_type = 'pairwise';
344 25
    }
345
346
    /**
347
     * @param mixed $id
348
     * @return $this
349
     */
350 4
    public function setId($id)
351
    {
352 4
        $this->id = $id;
353
354 4
        return $this;
355
    }
356
357
    /**
358
     * @return string[]
359
     */
360 4
    public function getRedirectUris()
361
    {
362 4
        return $this->redirect_uris;
363
    }
364
365 2
    public function setRedirectUris($redirect_uris)
366
    {
367 2
        $this->redirect_uris = $redirect_uris;
368
369 2
        return $this;
370
    }
371
372 1
    public function getResponseTypes()
373
    {
374 1
        return $this->response_types;
375
    }
376
377
    public function setResponseTypes($response_types)
378
    {
379
        $this->response_types = $response_types;
380
381
        return $this;
382
    }
383
384 4
    public function getGrantTypes()
385
    {
386 4
        return $this->grant_types;
387
    }
388
389 1
    public function setGrantTypes($grant_types)
390
    {
391 1
        $this->grant_types = $grant_types;
392
393 1
        return $this;
394
    }
395
396 1
    public function getApplicationType()
397
    {
398 1
        return $this->application_type;
399
    }
400
401
    public function setApplicationType($application_type)
402
    {
403
        $this->application_type = $application_type;
404
405
        return $this;
406
    }
407
408 5
    public function getContacts()
409
    {
410 5
        $owners = [];
411 5
        if ($this->getClient()) {
412 2
            $owners = array_map(
413
                function (PersonInterface $owner) {
414 1
                    return $owner->getEmail();
415 2
                },
416 2
                $this->getClient()->getOwners()->toArray()
417
            );
418
        }
419 5
        $contacts = is_array($this->contacts) ? $this->contacts : [];
0 ignored issues
show
introduced by
The condition is_array($this->contacts) is always false.
Loading history...
420
421 5
        return array_unique(array_merge($contacts, $owners));
422
    }
423
424 3
    public function setContacts($contacts)
425
    {
426 3
        $this->contacts = $contacts;
427
428 3
        return $this;
429
    }
430
431 5
    public function getClientName()
432
    {
433 5
        return $this->client_name;
434
    }
435
436 5
    public function setClientName($client_name)
437
    {
438 5
        $this->client_name = $client_name;
439
440 5
        return $this;
441
    }
442
443 1
    public function getLogoUri()
444
    {
445 1
        return $this->logo_uri;
446
    }
447
448 1
    public function setLogoUri($logo_uri)
449
    {
450 1
        $this->logo_uri = $logo_uri;
451
452 1
        return $this;
453
    }
454
455 5
    public function getClientUri()
456
    {
457 5
        return $this->client_uri;
458
    }
459
460 3
    public function setClientUri($client_uri)
461
    {
462 3
        $this->client_uri = $client_uri;
463
464 3
        return $this;
465
    }
466
467 1
    public function getPolicyUri()
468
    {
469 1
        return $this->policy_uri;
470
    }
471
472 1
    public function setPolicyUri($policy_uri)
473
    {
474 1
        $this->policy_uri = $policy_uri;
475
476 1
        return $this;
477
    }
478
479 4
    public function getTosUri()
480
    {
481 4
        return $this->tos_uri;
482
    }
483
484 2
    public function setTosUri($tos_uri)
485
    {
486 2
        $this->tos_uri = $tos_uri;
487
488 2
        return $this;
489
    }
490
491 1
    public function getJwksUri()
492
    {
493 1
        return $this->jwks_uri;
494
    }
495
496 1
    public function setJwksUri($jwks_uri)
497
    {
498 1
        $this->jwks_uri = $jwks_uri;
499
500 1
        return $this;
501
    }
502
503 1
    public function getJwks()
504
    {
505 1
        return $this->jwks;
506
    }
507
508 1
    public function setJwks($jwks)
509
    {
510 1
        $this->jwks = $jwks;
511
512 1
        return $this;
513
    }
514
515 4
    public function getSectorIdentifierUri()
516
    {
517 4
        return $this->sector_identifier_uri;
518
    }
519
520 3
    public function setSectorIdentifierUri($sector_identifier_uri)
521
    {
522 3
        $this->sector_identifier_uri = $sector_identifier_uri;
523
524 3
        return $this;
525
    }
526
527
    /**
528
     * @return string|null
529
     */
530 1
    public function getSubjectType()
531
    {
532 1
        return $this->subject_type;
533
    }
534
535
    /**
536
     * @param string $subject_type
537
     * @return ClientMetadata
538
     */
539
    public function setSubjectType($subject_type)
540
    {
541
        $this->subject_type = $subject_type;
542
543
        return $this;
544
    }
545
546 1
    public function getIdTokenSignedResponseAlg()
547
    {
548 1
        return $this->id_token_signed_response_alg;
549
    }
550
551 1
    public function setIdTokenSignedResponseAlg($id_token_signed_response_alg)
552
    {
553 1
        $this->id_token_signed_response_alg = $id_token_signed_response_alg;
554
555 1
        return $this;
556
    }
557
558
    public function getIdTokenEncryptedResponseAlg()
559
    {
560
        return $this->id_token_encrypted_response_alg;
561
    }
562
563 1
    public function setIdTokenEncryptedResponseAlg($id_token_encrypted_response_alg)
564
    {
565 1
        $this->id_token_encrypted_response_alg = $id_token_encrypted_response_alg;
566
567 1
        return $this;
568
    }
569
570
    public function getIdTokenEncryptedResponseEnc()
571
    {
572
        return $this->id_token_encrypted_response_enc;
573
    }
574
575 1
    public function setIdTokenEncryptedResponseEnc($id_token_encrypted_response_enc)
576
    {
577 1
        $this->id_token_encrypted_response_enc = $id_token_encrypted_response_enc;
578
579 1
        return $this;
580
    }
581
582
    public function getUserinfoSignedResponseAlg()
583
    {
584
        return $this->userinfo_signed_response_alg;
585
    }
586
587 1
    public function setUserinfoSignedResponseAlg($userinfo_signed_response_alg)
588
    {
589 1
        $this->userinfo_signed_response_alg = $userinfo_signed_response_alg;
590
591 1
        return $this;
592
    }
593
594
    public function getUserinfoEncryptedResponseAlg()
595
    {
596
        return $this->userinfo_encrypted_response_alg;
597
    }
598
599 1
    public function setUserinfoEncryptedResponseAlg($userinfo_encrypted_response_alg)
600
    {
601 1
        $this->userinfo_encrypted_response_alg = $userinfo_encrypted_response_alg;
602
603 1
        return $this;
604
    }
605
606
    public function getUserinfoEncryptedResponseEnc()
607
    {
608
        return $this->userinfo_encrypted_response_enc;
609
    }
610
611 1
    public function setUserinfoEncryptedResponseEnc($userinfo_encrypted_response_enc)
612
    {
613 1
        $this->userinfo_encrypted_response_enc = $userinfo_encrypted_response_enc;
614
615 1
        return $this;
616
    }
617
618
    public function getRequestObjectSigningAlg()
619
    {
620
        return $this->request_object_signing_alg;
621
    }
622
623 1
    public function setRequestObjectSigningAlg($request_object_signing_alg)
624
    {
625 1
        $this->request_object_signing_alg = $request_object_signing_alg;
626
627 1
        return $this;
628
    }
629
630
    public function getRequestObjectEncryptionAlg()
631
    {
632
        return $this->request_object_encryption_alg;
633
    }
634
635 1
    public function setRequestObjectEncryptionAlg($request_object_encryption_alg)
636
    {
637 1
        $this->request_object_encryption_alg = $request_object_encryption_alg;
638
639 1
        return $this;
640
    }
641
642
    public function getRequestObjectEncryptionEnc()
643
    {
644
        return $this->request_object_encryption_enc;
645
    }
646
647 1
    public function setRequestObjectEncryptionEnc($request_object_encryption_enc)
648
    {
649 1
        $this->request_object_encryption_enc = $request_object_encryption_enc;
650
651 1
        return $this;
652
    }
653
654 1
    public function getTokenEndpointAuthMethod()
655
    {
656 1
        return $this->token_endpoint_auth_method;
657
    }
658
659 1
    public function setTokenEndpointAuthMethod($token_endpoint_auth_method)
660
    {
661 1
        $this->token_endpoint_auth_method = $token_endpoint_auth_method;
662
663 1
        return $this;
664
    }
665
666
    public function getTokenEndpointAuthSigningAlg()
667
    {
668
        return $this->token_endpoint_auth_signing_alg;
669
    }
670
671 1
    public function setTokenEndpointAuthSigningAlg($token_endpoint_auth_signing_alg)
672
    {
673 1
        $this->token_endpoint_auth_signing_alg = $token_endpoint_auth_signing_alg;
674
675 1
        return $this;
676
    }
677
678 1
    public function getDefaultMaxAge()
679
    {
680 1
        return $this->default_max_age;
681
    }
682
683 1
    public function setDefaultMaxAge($default_max_age)
684
    {
685 1
        $this->default_max_age = $default_max_age;
686
687 1
        return $this;
688
    }
689
690 1
    public function getRequireAuthTime()
691
    {
692 1
        return $this->require_auth_time;
693
    }
694
695 1
    public function setRequireAuthTime($require_auth_time)
696
    {
697 1
        $this->require_auth_time = $require_auth_time;
698
699 1
        return $this;
700
    }
701
702
    public function getDefaultAcrValues()
703
    {
704
        return $this->default_acr_values;
705
    }
706
707
    /**
708
     * @param $default_acr_values
709
     * @return ClientMetadata
710
     */
711 1
    public function setDefaultAcrValues($default_acr_values)
712
    {
713 1
        $this->default_acr_values = $default_acr_values;
714
715 1
        return $this;
716
    }
717
718 2
    public function getInitiateLoginUri()
719
    {
720 2
        return $this->initiate_login_uri;
721
    }
722
723
    /**
724
     * @param $initiate_login_uri
725
     * @return ClientMetadata
726
     */
727 2
    public function setInitiateLoginUri($initiate_login_uri)
728
    {
729 2
        $this->initiate_login_uri = $initiate_login_uri;
730
731 2
        return $this;
732
    }
733
734
    public function getRequestUris()
735
    {
736
        return $this->request_uris;
737
    }
738
739
    public function setRequestUris($request_uris)
740
    {
741
        $this->request_uris = $request_uris;
742
743
        return $this;
744
    }
745
746
    /**
747
     * @JMS\Groups({"client_metadata"})
748
     * @JMS\VirtualProperty
749
     * @JMS\SerializedName("client_id")
750
     */
751 1
    public function getClientId()
752
    {
753 1
        if ($this->client_id === null && $this->client) {
754
            return $this->client->getClientId();
755
        }
756
757 1
        return $this->client_id;
758
    }
759
760 1
    public function setClientId($client_id)
761
    {
762 1
        $this->client_id = $client_id;
763
764 1
        return $this;
765
    }
766
767
    /**
768
     * @JMS\Groups({"client_metadata"})
769
     * @JMS\VirtualProperty
770
     * @JMS\SerializedName("client_secret")
771
     */
772 1
    public function getClientSecret()
773
    {
774 1
        if ($this->client_id === null && $this->client) {
775
            return $this->client->getClientSecret();
776
        }
777
778 1
        return $this->client_secret;
779
    }
780
781 1
    public function setClientSecret($client_secret)
782
    {
783 1
        $this->client_secret = $client_secret;
784
785 1
        return $this;
786
    }
787
788
    /**
789
     * @param Client $client
790
     * @return ClientMetadata
791
     */
792
    public function fromClient(Client $client)
793
    {
794
        $this->setGrantTypes($client->getAllowedGrantTypes())
795
            ->setClientUri($client->getSiteUrl())
796
            ->setTosUri($client->getTermsOfUseUrl())
797
            ->setClientName($client->getName())
798
            ->setRedirectUris($client->getRedirectUris());
799
800
        $this->setClientId($client->getPublicId())
801
            ->setClientSecret($client->getSecret());
802
803
        return $this;
804
    }
805
806
    /**
807
     * @return Client
808
     */
809 2
    public function toClient()
810
    {
811 2
        $grantTypes = $this->getGrantTypes();
812 2
        $clientUri = $this->getClientUri();
813 2
        $tosUri = $this->getTosUri();
814 2
        $clientName = $this->getClientName();
815 2
        $redirectUris = $this->getRedirectUris();
816
817 2
        $client = new Client();
818
819 2
        if ($grantTypes) {
820 2
            $client->setAllowedGrantTypes($grantTypes);
0 ignored issues
show
Bug introduced by
$grantTypes of type string is incompatible with the type array expected by parameter $grantTypes of FOS\OAuthServerBundle\Mo...:setAllowedGrantTypes(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

820
            $client->setAllowedGrantTypes(/** @scrutinizer ignore-type */ $grantTypes);
Loading history...
821
        }
822
823 2
        if ($clientUri) {
824
            $client->setLandingPageUrl($clientUri)
825
                ->setSiteUrl($clientUri);
826
        }
827
828 2
        if ($tosUri) {
829
            $client->setTermsOfUseUrl($tosUri);
830
        }
831
832 2
        if ($clientName) {
833
            $client->setName($clientName);
834
        }
835
836 2
        if (count($redirectUris) > 0) {
837
            $client->setRedirectUris($redirectUris);
838
        }
839
840 2
        $client->setVisible(false)
841 2
            ->setPublished(false);
842
843 2
        return $client;
844
    }
845
846 6
    public function getClient()
847
    {
848 6
        return $this->client;
849
    }
850
851 8
    public function setClient(ClientInterface $client)
852
    {
853 8
        $this->client = $client;
854
855 8
        return $this;
856
    }
857
858
    /**
859
     * @ORM\PrePersist()
860
     */
861 1
    public function checkDefaults()
862
    {
863 1
        $this->enforceDefaultGrantTypes();
864 1
        $this->enforceDefaultResponseTypes();
865 1
        $this->enforceDefaultApplicationType();
866 1
        $this->enforceDefaultRequireAuthTime();
867 1
        $this->enforceDefaultIdTokenSignedResponseAlg();
868 1
        $this->enforceDefaultTokenEndpointAuthMethod();
869 1
        $this->enforceValidSubjectType();
870 1
    }
871
872 1
    private function enforceDefaultGrantTypes()
873
    {
874 1
        if (!$this->getGrantTypes()) {
875
            $this->setGrantTypes(['authorization_code']);
876
        }
877 1
    }
878
879 1
    private function enforceDefaultResponseTypes()
880
    {
881 1
        if (!$this->getResponseTypes()) {
882
            $this->setResponseTypes(['code']);
883
        }
884 1
    }
885
886 1
    private function enforceDefaultApplicationType()
887
    {
888 1
        if (!$this->getApplicationType()) {
889
            $this->setApplicationType('web');
890
        }
891 1
    }
892
893 1
    private function enforceDefaultRequireAuthTime()
894
    {
895 1
        if (!$this->getRequireAuthTime()) {
896 1
            $this->setRequireAuthTime(false);
897
        }
898 1
    }
899
900 1
    private function enforceDefaultIdTokenSignedResponseAlg()
901
    {
902 1
        if (!$this->getIdTokenSignedResponseAlg()) {
903 1
            $this->setIdTokenSignedResponseAlg('RS256');
904
        }
905 1
    }
906
907 1
    private function enforceDefaultTokenEndpointAuthMethod()
908
    {
909 1
        if (!$this->getTokenEndpointAuthMethod()) {
910 1
            $this->setTokenEndpointAuthMethod('client_secret_basic');
911
        }
912 1
    }
913
914 1
    private function enforceValidSubjectType()
915
    {
916 1
        if (false === array_search($this->getSubjectType(), ['public', 'pairwise'])) {
917
            $this->setSubjectType('pairwise');
918
        }
919 1
    }
920
921 1
    public function getSectorIdentifier()
922
    {
923 1
        $siUri = $this->getSectorIdentifierUri();
924 1
        if ($siUri) {
925 1
            $uri = $siUri;
926
        } else {
927
            $uris = $this->getRedirectUris();
928
            $uri = reset($uris);
929
        }
930
931 1
        return parse_url($uri, PHP_URL_HOST);
932
    }
933
934 4
    public function getRegistrationAccessToken()
935
    {
936 4
        return $this->registration_access_token;
937
    }
938
939
    /**
940
     * @param string $registration_access_token
941
     * @return ClientMetadata
942
     */
943 4
    public function setRegistrationAccessToken($registration_access_token)
944
    {
945 4
        $this->registration_access_token = $registration_access_token;
946
947 4
        return $this;
948
    }
949
950
    /**
951
     * @return OrganizationInterface
952
     */
953 3
    public function getOrganization()
954
    {
955 3
        return $this->organization;
956
    }
957
958
    /**
959
     * @param OrganizationInterface $organization
960
     */
961 2
    public function setOrganization($organization = null)
962
    {
963 2
        $this->organization = $organization;
964 2
    }
965
966
    /**
967
     * @return array
968
     */
969 1
    public function getPostLogoutRedirectUris()
970
    {
971 1
        return array_map(
972 1
            function ($value) {
973 1
                return self::canonicalizeUri($value);
974 1
            },
975 1
            is_array($this->post_logout_redirect_uris) ? $this->post_logout_redirect_uris : []
0 ignored issues
show
introduced by
The condition is_array($this->post_logout_redirect_uris) is always false.
Loading history...
976
        );
977
    }
978
979
    /**
980
     * @param array
981
     * @return ClientMetadata
982
     */
983 1
    public function setPostLogoutRedirectUris($post_logout_redirect_uris)
984
    {
985 1
        $this->post_logout_redirect_uris = $post_logout_redirect_uris;
986
987 1
        return $this;
988
    }
989
990
    /**
991
     * Add trailing slashes
992
     * @param $uri
993
     * @return string
994
     */
995 1
    public static function canonicalizeUri($uri)
996
    {
997 1
        $parsed = parse_url($uri);
998 1
        if (array_key_exists('path', $parsed) === false) {
999
            $parsed['path'] = '/';
1000
        }
1001
1002 1
        return self::unparseUrl($parsed);
1003
    }
1004
1005 1
    private static function unparseUrl($parsed_url)
1006
    {
1007 1
        $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'].'://' : '';
1008 1
        $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
1009 1
        $port = isset($parsed_url['port']) ? ':'.$parsed_url['port'] : '';
1010 1
        $user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
1011 1
        $pass = isset($parsed_url['pass']) ? ':'.$parsed_url['pass'] : '';
1012 1
        $pass = ($user || $pass) ? "$pass@" : '';
1013 1
        $path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
1014 1
        $query = isset($parsed_url['query']) ? '?'.$parsed_url['query'] : '';
1015 1
        $fragment = isset($parsed_url['fragment']) ? '#'.$parsed_url['fragment'] : '';
1016
1017 1
        return "$scheme$user$pass$host$port$path$query$fragment";
1018
    }
1019
}
1020