Passed
Push — issue#772 ( a6e519 )
by Guilherme
11:21
created

ClientMetadata::getUserinfoEncryptedResponseEnc()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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

805
            $client->setAllowedGrantTypes(/** @scrutinizer ignore-type */ $grantTypes);
Loading history...
806
        }
807
808 5
        if ($clientUri) {
809
            $client->setLandingPageUrl($clientUri)
810
                ->setSiteUrl($clientUri);
811
        }
812
813 5
        if ($tosUri) {
814
            $client->setTermsOfUseUrl($tosUri);
815
        }
816
817 5
        if ($clientName) {
818
            $client->setName($clientName);
819
        }
820
821 5
        if (count($redirectUris) > 0) {
822 3
            $client->setRedirectUris($redirectUris);
823
        }
824
825 5
        $client->setVisible(false)
826 5
            ->setPublished(false);
827
828 5
        return $client;
829
    }
830
831 8
    public function getClient()
832
    {
833 8
        return $this->client;
834
    }
835
836 10
    public function setClient(ClientInterface $client)
837
    {
838 10
        $this->client = $client;
839
840 10
        return $this;
841
    }
842
843
    /**
844
     * @ORM\PrePersist()
845
     */
846 1
    public function checkDefaults()
847
    {
848 1
        if (!$this->getGrantTypes()) {
849 1
            $this->setGrantTypes(['authorization_code']);
850
        }
851
852 1
        if (!$this->getResponseTypes()) {
853 1
            $this->setResponseTypes(['code']);
854
        }
855
856 1
        if (!$this->getApplicationType()) {
857 1
            $this->setApplicationType('web');
858
        }
859
860 1
        if (!$this->getRequireAuthTime()) {
861 1
            $this->setRequireAuthTime(false);
862
        }
863
864 1
        if (!$this->getIdTokenSignedResponseAlg()) {
865 1
            $this->setIdTokenSignedResponseAlg('RS256');
866
        }
867
868 1
        if (!$this->getTokenEndpointAuthMethod()) {
869 1
            $this->setTokenEndpointAuthMethod('client_secret_basic');
870
        }
871 1
    }
872
873
    public function getSectorIdentifier()
874
    {
875
        $siUri = $this->getSectorIdentifierUri();
876
        if ($siUri) {
877
            $uri = $siUri;
878
        } else {
879
            $uris = $this->getRedirectUris();
880
            $uri = reset($uris);
881
        }
882
883
        return parse_url($uri, PHP_URL_HOST);
884
    }
885
886 6
    public function getRegistrationAccessToken()
887
    {
888 6
        return $this->registration_access_token;
889
    }
890
891
    /**
892
     * @param string $registration_access_token
893
     * @return ClientMetadata
894
     */
895 6
    public function setRegistrationAccessToken($registration_access_token)
896
    {
897 6
        $this->registration_access_token = $registration_access_token;
898
899 6
        return $this;
900
    }
901
902
    /**
903
     * @return OrganizationInterface
904
     */
905 3
    public function getOrganization()
906
    {
907 3
        return $this->organization;
908
    }
909
910
    /**
911
     * @param OrganizationInterface $organization
912
     */
913 2
    public function setOrganization($organization = null)
914
    {
915 2
        $this->organization = $organization;
916 2
    }
917
918
    /**
919
     * @return array
920
     */
921 3
    public function getPostLogoutRedirectUris()
922
    {
923 3
        return array_map(
924 3
            function ($value) {
925
                return self::canonicalizeUri($value);
926 3
            },
927 3
            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...
928
        );
929
    }
930
931
    /**
932
     * @param array
933
     * @return ClientMetadata
934
     */
935 3
    public function setPostLogoutRedirectUris($post_logout_redirect_uris)
936
    {
937 3
        $this->post_logout_redirect_uris = $post_logout_redirect_uris;
938
939 3
        return $this;
940
    }
941
942
    /**
943
     * Add trailing slashes
944
     */
945
    public static function canonicalizeUri($uri)
946
    {
947
        $parsed = parse_url($uri);
948
        if (array_key_exists('path', $parsed) === false) {
949
            $parsed['path'] = '/';
950
        }
951
        $unparsed = self::unparseUrl($parsed);
952
953
        return $unparsed;
954
    }
955
956
    private static function unparseUrl($parsed_url)
957
    {
958
        $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'].'://' : '';
959
        $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
960
        $port = isset($parsed_url['port']) ? ':'.$parsed_url['port'] : '';
961
        $user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
962
        $pass = isset($parsed_url['pass']) ? ':'.$parsed_url['pass'] : '';
963
        $pass = ($user || $pass) ? "$pass@" : '';
964
        $path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
965
        $query = isset($parsed_url['query']) ? '?'.$parsed_url['query'] : '';
966
        $fragment = isset($parsed_url['fragment']) ? '#'.$parsed_url['fragment']
967
            : '';
968
969
        return "$scheme$user$pass$host$port$path$query$fragment";
970
    }
971
}
972