Failed Conditions
Push — issue#777 ( 19a7c1 )
by Guilherme
08:25
created

ClientMetadata::setRequestObjectEncryptionAlg()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
ccs 0
cts 3
cp 0
crap 2
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 24
    public function __construct()
338
    {
339 24
        $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 24
        $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 24
        $this->application_type = 'web';
342 24
        $this->require_auth_time = false;
343 24
        $this->subject_type = 'pairwise';
344 24
    }
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 3
    public function getRedirectUris()
361
    {
362 3
        return $this->redirect_uris;
363
    }
364
365 1
    public function setRedirectUris($redirect_uris)
366
    {
367 1
        $this->redirect_uris = $redirect_uris;
368
369 1
        return $this;
370
    }
371
372
    public function getResponseTypes()
373
    {
374
        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 3
    public function getGrantTypes()
385
    {
386 3
        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
    public function getApplicationType()
397
    {
398
        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 4
    public function getContacts()
409
    {
410 4
        $owners = [];
411 4
        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 4
        $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 4
        return array_unique(array_merge($contacts, $owners));
422
    }
423
424 2
    public function setContacts($contacts)
425
    {
426 2
        $this->contacts = $contacts;
427
428 2
        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
    public function getLogoUri()
444
    {
445
        return $this->logo_uri;
446
    }
447
448
    public function setLogoUri($logo_uri)
449
    {
450
        $this->logo_uri = $logo_uri;
451
452
        return $this;
453
    }
454
455 4
    public function getClientUri()
456
    {
457 4
        return $this->client_uri;
458
    }
459
460 2
    public function setClientUri($client_uri)
461
    {
462 2
        $this->client_uri = $client_uri;
463
464 2
        return $this;
465
    }
466
467
    public function getPolicyUri()
468
    {
469
        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 3
    public function getTosUri()
480
    {
481 3
        return $this->tos_uri;
482
    }
483
484 1
    public function setTosUri($tos_uri)
485
    {
486 1
        $this->tos_uri = $tos_uri;
487
488 1
        return $this;
489
    }
490
491
    public function getJwksUri()
492
    {
493
        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
    public function getJwks()
504
    {
505
        return $this->jwks;
506
    }
507
508
    public function setJwks($jwks)
509
    {
510
        $this->jwks = $jwks;
511
512
        return $this;
513
    }
514
515 3
    public function getSectorIdentifierUri()
516
    {
517 3
        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
    /**
528
     * @return string|null
529
     */
530
    public function getSubjectType()
531
    {
532
        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
    public function getIdTokenSignedResponseAlg()
547
    {
548
        return $this->id_token_signed_response_alg;
549
    }
550
551
    public function setIdTokenSignedResponseAlg($id_token_signed_response_alg)
552
    {
553
        $this->id_token_signed_response_alg = $id_token_signed_response_alg;
554
555
        return $this;
556
    }
557
558
    public function getIdTokenEncryptedResponseAlg()
559
    {
560
        return $this->id_token_encrypted_response_alg;
561
    }
562
563
    public function setIdTokenEncryptedResponseAlg($id_token_encrypted_response_alg)
564
    {
565
        $this->id_token_encrypted_response_alg = $id_token_encrypted_response_alg;
566
567
        return $this;
568
    }
569
570
    public function getIdTokenEncryptedResponseEnc()
571
    {
572
        return $this->id_token_encrypted_response_enc;
573
    }
574
575
    public function setIdTokenEncryptedResponseEnc($id_token_encrypted_response_enc)
576
    {
577
        $this->id_token_encrypted_response_enc = $id_token_encrypted_response_enc;
578
579
        return $this;
580
    }
581
582
    public function getUserinfoSignedResponseAlg()
583
    {
584
        return $this->userinfo_signed_response_alg;
585
    }
586
587
    public function setUserinfoSignedResponseAlg($userinfo_signed_response_alg)
588
    {
589
        $this->userinfo_signed_response_alg = $userinfo_signed_response_alg;
590
591
        return $this;
592
    }
593
594
    public function getUserinfoEncryptedResponseAlg()
595
    {
596
        return $this->userinfo_encrypted_response_alg;
597
    }
598
599
    public function setUserinfoEncryptedResponseAlg($userinfo_encrypted_response_alg)
600
    {
601
        $this->userinfo_encrypted_response_alg = $userinfo_encrypted_response_alg;
602
603
        return $this;
604
    }
605
606
    public function getUserinfoEncryptedResponseEnc()
607
    {
608
        return $this->userinfo_encrypted_response_enc;
609
    }
610
611
    public function setUserinfoEncryptedResponseEnc($userinfo_encrypted_response_enc)
612
    {
613
        $this->userinfo_encrypted_response_enc = $userinfo_encrypted_response_enc;
614
615
        return $this;
616
    }
617
618
    public function getRequestObjectSigningAlg()
619
    {
620
        return $this->request_object_signing_alg;
621
    }
622
623
    public function setRequestObjectSigningAlg($request_object_signing_alg)
624
    {
625
        $this->request_object_signing_alg = $request_object_signing_alg;
626
627
        return $this;
628
    }
629
630
    public function getRequestObjectEncryptionAlg()
631
    {
632
        return $this->request_object_encryption_alg;
633
    }
634
635
    public function setRequestObjectEncryptionAlg($request_object_encryption_alg)
636
    {
637
        $this->request_object_encryption_alg = $request_object_encryption_alg;
638
639
        return $this;
640
    }
641
642
    public function getRequestObjectEncryptionEnc()
643
    {
644
        return $this->request_object_encryption_enc;
645
    }
646
647
    public function setRequestObjectEncryptionEnc($request_object_encryption_enc)
648
    {
649
        $this->request_object_encryption_enc = $request_object_encryption_enc;
650
651
        return $this;
652
    }
653
654
    public function getTokenEndpointAuthMethod()
655
    {
656
        return $this->token_endpoint_auth_method;
657
    }
658
659
    public function setTokenEndpointAuthMethod($token_endpoint_auth_method)
660
    {
661
        $this->token_endpoint_auth_method = $token_endpoint_auth_method;
662
663
        return $this;
664
    }
665
666
    public function getTokenEndpointAuthSigningAlg()
667
    {
668
        return $this->token_endpoint_auth_signing_alg;
669
    }
670
671
    public function setTokenEndpointAuthSigningAlg($token_endpoint_auth_signing_alg)
672
    {
673
        $this->token_endpoint_auth_signing_alg = $token_endpoint_auth_signing_alg;
674
675
        return $this;
676
    }
677
678
    public function getDefaultMaxAge()
679
    {
680
        return $this->default_max_age;
681
    }
682
683
    public function setDefaultMaxAge($default_max_age)
684
    {
685
        $this->default_max_age = $default_max_age;
686
687
        return $this;
688
    }
689
690
    public function getRequireAuthTime()
691
    {
692
        return $this->require_auth_time;
693
    }
694
695
    public function setRequireAuthTime($require_auth_time)
696
    {
697
        $this->require_auth_time = $require_auth_time;
698
699
        return $this;
700
    }
701
702
    public function getDefaultAcrValues()
703
    {
704
        return $this->default_acr_values;
705
    }
706
707
    public function setDefaultAcrValues($default_acr_values)
708
    {
709
        $this->default_acr_values = $default_acr_values;
710
711
        return $this;
712
    }
713
714 1
    public function getInitiateLoginUri()
715
    {
716 1
        return $this->initiate_login_uri;
717
    }
718
719 1
    public function setInitiateLoginUri($initiate_login_uri)
720
    {
721 1
        $this->initiate_login_uri = $initiate_login_uri;
722
723 1
        return $this;
724
    }
725
726
    public function getRequestUris()
727
    {
728
        return $this->request_uris;
729
    }
730
731
    public function setRequestUris($request_uris)
732
    {
733
        $this->request_uris = $request_uris;
734
735
        return $this;
736
    }
737
738
    /**
739
     * @JMS\Groups({"client_metadata"})
740
     * @JMS\VirtualProperty
741
     * @JMS\SerializedName("client_id")
742
     */
743
    public function getClientId()
744
    {
745
        if ($this->client_id === null && $this->client) {
746
            return $this->client->getClientId();
747
        }
748
749
        return $this->client_id;
750
    }
751
752
    public function setClientId($client_id)
753
    {
754
        $this->client_id = $client_id;
755
756
        return $this;
757
    }
758
759
    /**
760
     * @JMS\Groups({"client_metadata"})
761
     * @JMS\VirtualProperty
762
     * @JMS\SerializedName("client_secret")
763
     */
764
    public function getClientSecret()
765
    {
766
        if ($this->client_id === null && $this->client) {
767
            return $this->client->getClientSecret();
768
        }
769
770
        return $this->client_secret;
771
    }
772
773
    public function setClientSecret($client_secret)
774
    {
775
        $this->client_secret = $client_secret;
776
777
        return $this;
778
    }
779
780
    /**
781
     * @param Client $client
782
     * @return ClientMetadata
783
     */
784
    public function fromClient(Client $client)
785
    {
786
        $this->setGrantTypes($client->getAllowedGrantTypes())
787
            ->setClientUri($client->getSiteUrl())
788
            ->setTosUri($client->getTermsOfUseUrl())
789
            ->setClientName($client->getName())
790
            ->setRedirectUris($client->getRedirectUris());
791
792
        $this->setClientId($client->getPublicId())
793
            ->setClientSecret($client->getSecret());
794
795
        return $this;
796
    }
797
798
    /**
799
     * @return Client
800
     */
801 2
    public function toClient()
802
    {
803 2
        $grantTypes = $this->getGrantTypes();
804 2
        $clientUri = $this->getClientUri();
805 2
        $tosUri = $this->getTosUri();
806 2
        $clientName = $this->getClientName();
807 2
        $redirectUris = $this->getRedirectUris();
808
809 2
        $client = new Client();
810
811 2
        if ($grantTypes) {
812 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

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