Failed Conditions
Push — issue#666 ( f415d0...521a08 )
by Guilherme
12:02
created

ClientMetadata::getSectorIdentifierUri()   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
    protected $id;
40
    protected $client_id;
41
    protected $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
    protected $client;
49
50
    /**
51
     * @JMS\Expose
52
     * @JMS\Groups({"client_metadata"})
53
     * @Assert\All({
54
     *      @Assert\Type(type="string"),
55
     *      @Assert\NotBlank,
56
     *      @Assert\Url(checkDNS = false)
57
     * })
58
     * @ORM\Column(name="redirect_uris", type="json_array", nullable=false)
59
     */
60
    protected $redirect_uris;
61
62
    /**
63
     * @JMS\Expose
64
     * @JMS\Groups({"client_metadata"})
65
     * @Assert\All({
66
     *      @Assert\Type("string")
67
     * })
68
     * @ORM\Column(name="response_types", type="simple_array", nullable=false)
69
     */
70
    protected $response_types = array('code');
71
72
    /**
73
     * @JMS\Expose
74
     * @JMS\Groups({"client_metadata"})
75
     * @Assert\All({
76
     *      @Assert\Type("string")
77
     * })
78
     * @ORM\Column(type="simple_array", nullable=false)
79
     */
80
    protected $grant_types = array('authorization_code');
81
82
    /**
83
     * @JMS\Expose
84
     * @JMS\Groups({"client_metadata"})
85
     * @Assert\Type(type="string")
86
     * @ORM\Column(name="application_type", type="string", length=100, nullable=false)
87
     */
88
    protected $application_type = 'web';
89
90
    /**
91
     * @JMS\Expose
92
     * @JMS\Groups({"client_metadata"})
93
     * @Assert\All({
94
     *      @Assert\Type("string")
95
     * })
96
     * @ORM\Column(type="simple_array", nullable=true)
97
     */
98
    protected $contacts;
99
100
    /**
101
     * @JMS\Expose
102
     * @JMS\Groups({"client_metadata"})
103
     * @Assert\Type(type="string")
104
     * @ORM\Column(type="string", nullable=true)
105
     */
106
    protected $client_name;
107
108
    /**
109
     * @JMS\Expose
110
     * @JMS\Groups({"client_metadata"})
111
     * @Assert\Type(type="string")
112
     * @Assert\Url(checkDNS = false)
113
     * @ORM\Column(type="string", length=2000, nullable=true)
114
     */
115
    protected $logo_uri;
116
117
    /**
118
     * @JMS\Expose
119
     * @JMS\Groups({"client_metadata"})
120
     * @Assert\Type(type="string")
121
     * @Assert\Url(checkDNS = false)
122
     * @ORM\Column(type="string", length=2000, nullable=true)
123
     */
124
    protected $client_uri;
125
126
    /**
127
     * @JMS\Expose
128
     * @JMS\Groups({"client_metadata"})
129
     * @Assert\Type(type="string")
130
     * @Assert\Url(checkDNS = false)
131
     * @ORM\Column(type="string", length=2000, nullable=true)
132
     */
133
    protected $policy_uri;
134
135
    /**
136
     * @JMS\Expose
137
     * @JMS\Groups({"client_metadata"})
138
     * @Assert\Url(checkDNS = false)
139
     * @Assert\Type(type="string")
140
     * @ORM\Column(type="string", length=2000, nullable=true)
141
     */
142
    protected $tos_uri;
143
144
    /**
145
     * @JMS\Expose
146
     * @JMS\Groups({"client_metadata"})
147
     * @Assert\Url(checkDNS = false)
148
     * @Assert\Type(type="string")
149
     * @ORM\Column(type="string", length=2000, nullable=true)
150
     */
151
    protected $jwks_uri;
152
153
    /**
154
     * @JMS\Expose
155
     * @JMS\Groups({"client_metadata"})
156
     * @Assert\Type(type="string")
157
     * @ORM\Column(type="text", nullable=true)
158
     */
159
    protected $jwks;
160
161
    /**
162
     * @JMS\Expose
163
     * @JMS\Groups({"client_metadata"})
164
     * @Assert\Url(checkDNS = false, protocols = {"http", "https"})
165
     * @Assert\Type(type="string")
166
     * @ORM\Column(type="string", length=2000, nullable=true)
167
     */
168
    protected $sector_identifier_uri;
169
170
    /**
171
     * @JMS\Expose
172
     * @JMS\Groups({"client_metadata"})
173
     * @Assert\Type(type="string")
174
     * @ORM\Column(type="string", length=20, nullable=true)
175
     */
176
    protected $subject_type;
177
178
    /**
179
     * @JMS\Expose
180
     * @JMS\Groups({"client_metadata"})
181
     * @Assert\Type(type="string")
182
     * @ORM\Column(type="string", length=50, nullable=true)
183
     */
184
    protected $id_token_signed_response_alg;
185
186
    /**
187
     * @JMS\Expose
188
     * @JMS\Groups({"client_metadata"})
189
     * @Assert\Type(type="string")
190
     * @ORM\Column(type="string", length=50, nullable=true)
191
     */
192
    protected $id_token_encrypted_response_alg;
193
194
    /**
195
     * @JMS\Expose
196
     * @JMS\Groups({"client_metadata"})
197
     * @Assert\Type(type="string")
198
     * @ORM\Column(type="string", length=50, nullable=true)
199
     */
200
    protected $id_token_encrypted_response_enc;
201
202
    /**
203
     * @JMS\Expose
204
     * @JMS\Groups({"client_metadata"})
205
     * @Assert\Type(type="string")
206
     * @ORM\Column(type="string", length=50, nullable=true)
207
     */
208
    protected $userinfo_signed_response_alg;
209
210
    /**
211
     * @JMS\Expose
212
     * @JMS\Groups({"client_metadata"})
213
     * @Assert\Type(type="string")
214
     * @ORM\Column(type="string", length=50, nullable=true)
215
     */
216
    protected $userinfo_encrypted_response_alg;
217
218
    /**
219
     * @JMS\Expose
220
     * @JMS\Groups({"client_metadata"})
221
     * @Assert\Type(type="string")
222
     * @ORM\Column(type="string", length=50, nullable=true)
223
     */
224
    protected $userinfo_encrypted_response_enc;
225
226
    /**
227
     * @JMS\Expose
228
     * @JMS\Groups({"client_metadata"})
229
     * @Assert\Type(type="string")
230
     * @ORM\Column(type="string", length=50, nullable=true)
231
     */
232
    protected $request_object_signing_alg;
233
234
    /**
235
     * @JMS\Expose
236
     * @JMS\Groups({"client_metadata"})
237
     * @Assert\Type(type="string")
238
     * @ORM\Column(type="string", length=50, nullable=true)
239
     */
240
    protected $request_object_encryption_alg;
241
242
    /**
243
     * @JMS\Expose
244
     * @JMS\Groups({"client_metadata"})
245
     * @Assert\Type(type="string")
246
     * @ORM\Column(type="string", length=50, nullable=true)
247
     */
248
    protected $request_object_encryption_enc;
249
250
    /**
251
     * @JMS\Expose
252
     * @JMS\Groups({"client_metadata"})
253
     * @Assert\Type(type="string")
254
     * @ORM\Column(type="string", length=50, nullable=true)
255
     */
256
    protected $token_endpoint_auth_method;
257
258
    /**
259
     * @JMS\Expose
260
     * @JMS\Groups({"client_metadata"})
261
     * @Assert\Type(type="string")
262
     * @ORM\Column(type="string", length=50, nullable=true)
263
     */
264
    protected $token_endpoint_auth_signing_alg;
265
266
    /**
267
     * @JMS\Expose
268
     * @JMS\Groups({"client_metadata"})
269
     * @Assert\Type(type="integer")
270
     * @ORM\Column(type="integer", nullable=true)
271
     */
272
    protected $default_max_age;
273
274
    /**
275
     * @JMS\Expose
276
     * @JMS\Groups({"client_metadata"})
277
     * @Assert\Type(type="boolean")
278
     */
279
    protected $require_auth_time = false;
280
281
    /**
282
     * @JMS\Expose
283
     * @JMS\Groups({"client_metadata"})
284
     * @Assert\Type(type="array")
285
     * @ORM\Column(type="simple_array", nullable=true)
286
     */
287
    protected $default_acr_values;
288
289
    /**
290
     * @JMS\Expose
291
     * @JMS\Groups({"client_metadata"})
292
     * @Assert\Url(checkDNS = false)
293
     * @Assert\Type(type="string")
294
     * @ORM\Column(type="string", length=2000, nullable=true)
295
     */
296
    protected $initiate_login_uri;
297
298
    /**
299
     * @JMS\Expose
300
     * @JMS\Groups({"client_metadata"})
301
     * @Assert\All({
302
     *      @Assert\Type("string"),
303
     *      @Assert\Url(checkDNS = false)
304
     * })
305
     * @ORM\Column(type="simple_array", nullable=true)
306
     */
307
    protected $request_uris;
308
309
    /**
310
     * @JMS\Expose
311
     * @JMS\Groups({"client_metadata"})
312
     * @Assert\Type(type="string")
313
     * @ORM\Column(type="string", nullable=true)
314
     */
315
    protected $registration_access_token;
316
317
    /**
318
     * @var OrganizationInterface
319
     * @ORM\ManyToOne(targetEntity="LoginCidadao\OAuthBundle\Model\OrganizationInterface", inversedBy="clients")
320
     * @ORM\JoinColumn(name="organization_id", referencedColumnName="id", onDelete="SET NULL")
321
     */
322
    protected $organization;
323
324
    /**
325
     * @JMS\Expose
326
     * @JMS\Groups({"client_metadata"})
327
     * @Assert\All({
328
     *      @Assert\Type("string"),
329
     *      @Assert\Url(checkDNS = false)
330
     * })
331
     * @ORM\Column(type="simple_array", nullable=true)
332
     */
333
    protected $post_logout_redirect_uris;
334
335 27
    public function __construct()
336
    {
337 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...
338 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...
339 27
        $this->application_type = 'web';
340 27
        $this->require_auth_time = false;
341 27
        $this->subject_type = 'pairwise';
342 27
    }
343
344
    /**
345
     * @param mixed $id
346
     * @return $this
347
     */
348 3
    public function setId($id)
349
    {
350 3
        $this->id = $id;
351
352 3
        return $this;
353
    }
354
355 6
    public function getRedirectUris()
356
    {
357 6
        return $this->redirect_uris;
358
    }
359
360 4
    public function setRedirectUris($redirect_uris)
361
    {
362 4
        $this->redirect_uris = $redirect_uris;
363
364 4
        return $this;
365
    }
366
367 3
    public function getResponseTypes()
368
    {
369 3
        return $this->response_types;
370
    }
371
372 3
    public function setResponseTypes($response_types)
373
    {
374 3
        $this->response_types = $response_types;
375
376 3
        return $this;
377
    }
378
379 6
    public function getGrantTypes()
380
    {
381 6
        return $this->grant_types;
382
    }
383
384 4
    public function setGrantTypes($grant_types)
385
    {
386 4
        $this->grant_types = $grant_types;
387
388 4
        return $this;
389
    }
390
391 3
    public function getApplicationType()
392
    {
393 3
        return $this->application_type;
394
    }
395
396 3
    public function setApplicationType($application_type)
397
    {
398 3
        $this->application_type = $application_type;
399
400 3
        return $this;
401
    }
402
403 7
    public function getContacts()
404
    {
405 7
        $owners = [];
406 7
        if ($this->getClient()) {
407 1
            $owners = array_map(
408
                function (PersonInterface $owner) {
409
                    return $owner->getEmail();
410 1
                },
411 1
                $this->getClient()->getOwners()->toArray()
412
            );
413
        }
414 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...
415
416 7
        return array_unique(array_merge($contacts, $owners));
417
    }
418
419 5
    public function setContacts($contacts)
420
    {
421 5
        $this->contacts = $contacts;
422
423 5
        return $this;
424
    }
425
426 8
    public function getClientName()
427
    {
428 8
        return $this->client_name;
429
    }
430
431 8
    public function setClientName($client_name)
432
    {
433 8
        $this->client_name = $client_name;
434
435 8
        return $this;
436
    }
437
438 3
    public function getLogoUri()
439
    {
440 3
        return $this->logo_uri;
441
    }
442
443 1
    public function setLogoUri($logo_uri)
444
    {
445 1
        $this->logo_uri = $logo_uri;
446
447 1
        return $this;
448
    }
449
450 7
    public function getClientUri()
451
    {
452 7
        return $this->client_uri;
453
    }
454
455 3
    public function setClientUri($client_uri)
456
    {
457 3
        $this->client_uri = $client_uri;
458
459 3
        return $this;
460
    }
461
462 3
    public function getPolicyUri()
463
    {
464 3
        return $this->policy_uri;
465
    }
466
467
    public function setPolicyUri($policy_uri)
468
    {
469
        $this->policy_uri = $policy_uri;
470
471
        return $this;
472
    }
473
474 6
    public function getTosUri()
475
    {
476 6
        return $this->tos_uri;
477
    }
478
479 2
    public function setTosUri($tos_uri)
480
    {
481 2
        $this->tos_uri = $tos_uri;
482
483 2
        return $this;
484
    }
485
486 3
    public function getJwksUri()
487
    {
488 3
        return $this->jwks_uri;
489
    }
490
491
    public function setJwksUri($jwks_uri)
492
    {
493
        $this->jwks_uri = $jwks_uri;
494
495
        return $this;
496
    }
497
498 3
    public function getJwks()
499
    {
500 3
        return $this->jwks;
501
    }
502
503
    public function setJwks($jwks)
504
    {
505
        $this->jwks = $jwks;
506
507
        return $this;
508
    }
509
510 6
    public function getSectorIdentifierUri()
511
    {
512 6
        return $this->sector_identifier_uri;
513
    }
514
515 2
    public function setSectorIdentifierUri($sector_identifier_uri)
516
    {
517 2
        $this->sector_identifier_uri = $sector_identifier_uri;
518
519 2
        return $this;
520
    }
521
522 3
    public function getSubjectType()
523
    {
524 3
        return $this->subject_type;
525
    }
526
527 3
    public function setSubjectType($subject_type)
528
    {
529 3
        $this->subject_type = $subject_type;
530
531 3
        return $this;
532
    }
533
534 3
    public function getIdTokenSignedResponseAlg()
535
    {
536 3
        return $this->id_token_signed_response_alg;
537
    }
538
539 1
    public function setIdTokenSignedResponseAlg($id_token_signed_response_alg)
540
    {
541 1
        $this->id_token_signed_response_alg = $id_token_signed_response_alg;
542
543 1
        return $this;
544
    }
545
546 3
    public function getIdTokenEncryptedResponseAlg()
547
    {
548 3
        return $this->id_token_encrypted_response_alg;
549
    }
550
551
    public function setIdTokenEncryptedResponseAlg($id_token_encrypted_response_alg)
552
    {
553
        $this->id_token_encrypted_response_alg = $id_token_encrypted_response_alg;
554
555
        return $this;
556
    }
557
558 3
    public function getIdTokenEncryptedResponseEnc()
559
    {
560 3
        return $this->id_token_encrypted_response_enc;
561
    }
562
563
    public function setIdTokenEncryptedResponseEnc($id_token_encrypted_response_enc)
564
    {
565
        $this->id_token_encrypted_response_enc = $id_token_encrypted_response_enc;
566
567
        return $this;
568
    }
569
570 3
    public function getUserinfoSignedResponseAlg()
571
    {
572 3
        return $this->userinfo_signed_response_alg;
573
    }
574
575
    public function setUserinfoSignedResponseAlg($userinfo_signed_response_alg)
576
    {
577
        $this->userinfo_signed_response_alg = $userinfo_signed_response_alg;
578
579
        return $this;
580
    }
581
582 3
    public function getUserinfoEncryptedResponseAlg()
583
    {
584 3
        return $this->userinfo_encrypted_response_alg;
585
    }
586
587
    public function setUserinfoEncryptedResponseAlg($userinfo_encrypted_response_alg)
588
    {
589
        $this->userinfo_encrypted_response_alg = $userinfo_encrypted_response_alg;
590
591
        return $this;
592
    }
593
594 3
    public function getUserinfoEncryptedResponseEnc()
595
    {
596 3
        return $this->userinfo_encrypted_response_enc;
597
    }
598
599
    public function setUserinfoEncryptedResponseEnc($userinfo_encrypted_response_enc)
600
    {
601
        $this->userinfo_encrypted_response_enc = $userinfo_encrypted_response_enc;
602
603
        return $this;
604
    }
605
606 3
    public function getRequestObjectSigningAlg()
607
    {
608 3
        return $this->request_object_signing_alg;
609
    }
610
611
    public function setRequestObjectSigningAlg($request_object_signing_alg)
612
    {
613
        $this->request_object_signing_alg = $request_object_signing_alg;
614
615
        return $this;
616
    }
617
618 3
    public function getRequestObjectEncryptionAlg()
619
    {
620 3
        return $this->request_object_encryption_alg;
621
    }
622
623
    public function setRequestObjectEncryptionAlg($request_object_encryption_alg)
624
    {
625
        $this->request_object_encryption_alg = $request_object_encryption_alg;
626
627
        return $this;
628
    }
629
630 3
    public function getRequestObjectEncryptionEnc()
631
    {
632 3
        return $this->request_object_encryption_enc;
633
    }
634
635
    public function setRequestObjectEncryptionEnc($request_object_encryption_enc)
636
    {
637
        $this->request_object_encryption_enc = $request_object_encryption_enc;
638
639
        return $this;
640
    }
641
642 3
    public function getTokenEndpointAuthMethod()
643
    {
644 3
        return $this->token_endpoint_auth_method;
645
    }
646
647 1
    public function setTokenEndpointAuthMethod($token_endpoint_auth_method)
648
    {
649 1
        $this->token_endpoint_auth_method = $token_endpoint_auth_method;
650
651 1
        return $this;
652
    }
653
654 3
    public function getTokenEndpointAuthSigningAlg()
655
    {
656 3
        return $this->token_endpoint_auth_signing_alg;
657
    }
658
659
    public function setTokenEndpointAuthSigningAlg($token_endpoint_auth_signing_alg)
660
    {
661
        $this->token_endpoint_auth_signing_alg = $token_endpoint_auth_signing_alg;
662
663
        return $this;
664
    }
665
666 3
    public function getDefaultMaxAge()
667
    {
668 3
        return $this->default_max_age;
669
    }
670
671
    public function setDefaultMaxAge($default_max_age)
672
    {
673
        $this->default_max_age = $default_max_age;
674
675
        return $this;
676
    }
677
678 3
    public function getRequireAuthTime()
679
    {
680 3
        return $this->require_auth_time;
681
    }
682
683 1
    public function setRequireAuthTime($require_auth_time)
684
    {
685 1
        $this->require_auth_time = $require_auth_time;
686
687 1
        return $this;
688
    }
689
690 3
    public function getDefaultAcrValues()
691
    {
692 3
        return $this->default_acr_values;
693
    }
694
695 3
    public function setDefaultAcrValues($default_acr_values)
696
    {
697 3
        $this->default_acr_values = $default_acr_values;
698
699 3
        return $this;
700
    }
701
702 4
    public function getInitiateLoginUri()
703
    {
704 4
        return $this->initiate_login_uri;
705
    }
706
707 1
    public function setInitiateLoginUri($initiate_login_uri)
708
    {
709 1
        $this->initiate_login_uri = $initiate_login_uri;
710
711 1
        return $this;
712
    }
713
714 3
    public function getRequestUris()
715
    {
716 3
        return $this->request_uris;
717
    }
718
719
    public function setRequestUris($request_uris)
720
    {
721
        $this->request_uris = $request_uris;
722
723
        return $this;
724
    }
725
726
    /**
727
     * @JMS\Groups({"client_metadata"})
728
     * @JMS\VirtualProperty
729
     * @JMS\SerializedName("client_id")
730
     */
731 3
    public function getClientId()
732
    {
733 3
        if ($this->client_id === null && $this->client) {
734
            return $this->client->getClientId();
735
        }
736
737 3
        return $this->client_id;
738
    }
739
740 1
    public function setClientId($client_id)
741
    {
742 1
        $this->client_id = $client_id;
743
744 1
        return $this;
745
    }
746
747
    /**
748
     * @JMS\Groups({"client_metadata"})
749
     * @JMS\VirtualProperty
750
     * @JMS\SerializedName("client_secret")
751
     */
752 3
    public function getClientSecret()
753
    {
754 3
        if ($this->client_id === null && $this->client) {
755
            return $this->client->getClientSecret();
756
        }
757
758 3
        return $this->client_secret;
759
    }
760
761 1
    public function setClientSecret($client_secret)
762
    {
763 1
        $this->client_secret = $client_secret;
764
765 1
        return $this;
766
    }
767
768
    /**
769
     * @param Client $client
770
     * @return ClientMetadata
771
     */
772 1
    public function fromClient(Client $client)
773
    {
774 1
        $this->setGrantTypes($client->getAllowedGrantTypes())
775 1
            ->setClientUri($client->getSiteUrl())
776 1
            ->setTosUri($client->getTermsOfUseUrl())
777 1
            ->setClientName($client->getName())
778 1
            ->setRedirectUris($client->getRedirectUris());
779
780 1
        $this->setClientId($client->getPublicId())
781 1
            ->setClientSecret($client->getSecret());
782
783 1
        return $this;
784
    }
785
786
    /**
787
     * @return Client
788
     */
789 5
    public function toClient()
790
    {
791 5
        $grantTypes = $this->getGrantTypes();
792 5
        $clientUri = $this->getClientUri();
793 5
        $tosUri = $this->getTosUri();
794 5
        $clientName = $this->getClientName();
795 5
        $redirectUris = $this->getRedirectUris();
796
797 5
        $client = new Client();
798
799 5
        if ($grantTypes) {
800 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

800
            $client->setAllowedGrantTypes(/** @scrutinizer ignore-type */ $grantTypes);
Loading history...
801
        }
802
803 5
        if ($clientUri) {
804
            $client->setLandingPageUrl($clientUri)
805
                ->setSiteUrl($clientUri);
806
        }
807
808 5
        if ($tosUri) {
809
            $client->setTermsOfUseUrl($tosUri);
810
        }
811
812 5
        if ($clientName) {
813
            $client->setName($clientName);
814
        }
815
816 5
        if ($redirectUris) {
817 3
            $client->setRedirectUris($redirectUris);
0 ignored issues
show
Bug introduced by
$redirectUris of type string is incompatible with the type array expected by parameter $redirectUris of LoginCidadao\OAuthBundle...ient::setRedirectUris(). ( Ignorable by Annotation )

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

817
            $client->setRedirectUris(/** @scrutinizer ignore-type */ $redirectUris);
Loading history...
818
        }
819
820 5
        $client->setVisible(false)
821 5
            ->setPublished(false);
822
823 5
        return $client;
824
    }
825
826 8
    public function getClient()
827
    {
828 8
        return $this->client;
829
    }
830
831 10
    public function setClient(ClientInterface $client)
832
    {
833 10
        $this->client = $client;
834
835 10
        return $this;
836
    }
837
838
    /**
839
     * @ORM\PrePersist()
840
     */
841 1
    public function checkDefaults()
842
    {
843 1
        if (!$this->getGrantTypes()) {
844 1
            $this->setGrantTypes(array('authorization_code'));
845
        }
846
847 1
        if (!$this->getResponseTypes()) {
848 1
            $this->setResponseTypes(array('code'));
849
        }
850
851 1
        if (!$this->getApplicationType()) {
852 1
            $this->setApplicationType('web');
853
        }
854
855 1
        if (!$this->getRequireAuthTime()) {
856 1
            $this->setRequireAuthTime(false);
857
        }
858
859 1
        if (!$this->getIdTokenSignedResponseAlg()) {
860 1
            $this->setIdTokenSignedResponseAlg('RS256');
861
        }
862
863 1
        if (!$this->getTokenEndpointAuthMethod()) {
864 1
            $this->setTokenEndpointAuthMethod('client_secret_basic');
865
        }
866 1
    }
867
868
    public function getSectorIdentifier()
869
    {
870
        $siUri = $this->getSectorIdentifierUri();
871
        if ($siUri) {
872
            $uri = $siUri;
873
        } else {
874
            $uris = $this->getRedirectUris();
875
            $uri = reset($uris);
0 ignored issues
show
Bug introduced by
$uris of type string is incompatible with the type array expected by parameter $array of reset(). ( Ignorable by Annotation )

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

875
            $uri = reset(/** @scrutinizer ignore-type */ $uris);
Loading history...
876
        }
877
878
        return parse_url($uri, PHP_URL_HOST);
879
    }
880
881
    public function getRegistrationAccessToken()
882
    {
883
        return $this->registration_access_token;
884
    }
885
886
    /**
887
     * @return OrganizationInterface
888
     */
889 3
    public function getOrganization()
890
    {
891 3
        return $this->organization;
892
    }
893
894
    /**
895
     * @param OrganizationInterface $organization
896
     */
897 2
    public function setOrganization($organization = null)
898
    {
899 2
        $this->organization = $organization;
900 2
    }
901
902
    /**
903
     * @return array
904
     */
905 3
    public function getPostLogoutRedirectUris()
906
    {
907 3
        return array_map(
908 3
            function ($value) {
909
                return self::canonicalizeUri($value);
910 3
            },
911 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...
912
        );
913
    }
914
915
    /**
916
     * @param array
917
     * @return ClientMetadata
918
     */
919 3
    public function setPostLogoutRedirectUris($post_logout_redirect_uris)
920
    {
921 3
        $this->post_logout_redirect_uris = $post_logout_redirect_uris;
922
923 3
        return $this;
924
    }
925
926
    /**
927
     * Add trailing slashes
928
     */
929
    public static function canonicalizeUri($uri)
930
    {
931
        $parsed = parse_url($uri);
932
        if (array_key_exists('path', $parsed) === false) {
933
            $parsed['path'] = '/';
934
        }
935
        $unparsed = self::unparseUrl($parsed);
936
937
        return $unparsed;
938
    }
939
940
    private static function unparseUrl($parsed_url)
941
    {
942
        $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'].'://' : '';
943
        $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
944
        $port = isset($parsed_url['port']) ? ':'.$parsed_url['port'] : '';
945
        $user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
946
        $pass = isset($parsed_url['pass']) ? ':'.$parsed_url['pass'] : '';
947
        $pass = ($user || $pass) ? "$pass@" : '';
948
        $path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
949
        $query = isset($parsed_url['query']) ? '?'.$parsed_url['query'] : '';
950
        $fragment = isset($parsed_url['fragment']) ? '#'.$parsed_url['fragment']
951
            : '';
952
953
        return "$scheme$user$pass$host$port$path$query$fragment";
954
    }
955
}
956