@@ -63,6 +63,12 @@ public function __construct(
6363 */
6464 public function verifiableCredentialIssuance (Request $ request ): Response
6565 {
66+ $ setupErrors = [];
67+
68+ if (!$ this ->moduleConfig ->getVerifiableCredentialEnabled ()) {
69+ $ setupErrors [] = 'Verifiable Credential functionalities are not enabled. ' ;
70+ }
71+
6672 $ selectedAuthSourceId = $ this ->sessionService ->getCurrentSession ()->getData ('vci ' , 'auth_source_id ' );
6773
6874 $ authSource = null ;
@@ -85,20 +91,46 @@ public function verifiableCredentialIssuance(Request $request): Response
8591 $ selectedAuthSourceId = $ newAuthSourceId ;
8692 }
8793
94+ $ authSourceIds = array_filter (
95+ $ this ->sspBridge ->auth ()->source ()->getSources (),
96+ fn (string $ authSourceId ): bool => $ authSourceId !== 'admin ' ,
97+ );
8898
8999 if (
90100 $ authSource instanceof Simple &&
91101 ($ authSource ->isAuthenticated () === false ) &&
92- is_string ($ selectedAuthSourceId )
102+ is_string ($ selectedAuthSourceId ) &&
103+ in_array ($ selectedAuthSourceId , $ authSourceIds , true )
93104 ) {
94105 $ authSource ->login (['ReturnTo ' => $ this ->routes ->urlAdminTestVerifiableCredentialIssuance ()]);
95106 }
96107
97- $ authSourceIds = array_filter (
98- $ this -> sspBridge -> auth ()-> source ()-> getSources () ,
99- fn ( string $ authSourceId ): bool => $ authSourceId !== ' admin ' ,
108+ $ selectedCredentialConfigurationId = $ this -> sessionService -> getCurrentSession ()-> getData (
109+ ' vci ' ,
110+ ' credential_configuration_id ' ,
100111 );
101112
113+ if (is_string ($ newCredentialConfigurationId = $ request ->get ('credentialConfigurationId ' ))) {
114+ $ this ->sessionService ->getCurrentSession ()->setData (
115+ 'vci ' ,
116+ 'credential_configuration_id ' ,
117+ $ newCredentialConfigurationId ,
118+ );
119+ $ selectedCredentialConfigurationId = $ newCredentialConfigurationId ;
120+ }
121+
122+ $ credentialConfigurationIdsSupported = $ this ->moduleConfig ->getCredentialConfigurationIdsSupported ();
123+
124+ if (empty ($ credentialConfigurationIdsSupported )) {
125+ $ setupErrors [] = 'No credential configuration IDs configured. ' ;
126+ }
127+
128+ if (
129+ is_null ($ selectedCredentialConfigurationId ) ||
130+ !in_array ($ selectedCredentialConfigurationId , $ credentialConfigurationIdsSupported , true )
131+ ) {
132+ $ selectedCredentialConfigurationId = current ($ credentialConfigurationIdsSupported );
133+ }
102134
103135 $ credentialOfferQrUri = null ;
104136 $ credentialOfferUri = null ;
@@ -147,19 +179,23 @@ public function verifiableCredentialIssuance(Request $request): Response
147179 $ clientId = '1234567890 ' ;
148180 $ clientSecret = '1234567890 ' ;
149181
150- if (($ client = $ this ->clientRepository ->findById ($ clientId )) === null ) {
151- $ client = $ this ->clientEntityFactory ->fromData (
152- id: $ clientId ,
153- secret: $ clientSecret ,
154- name: 'VCI Pre-authorized Code Test Client ' ,
155- description: 'Test client for VCI Pre-authorized Code ' ,
156- redirectUri: ['https://example.com/oidc/callback ' ],
157- scopes: ['openid ' , 'ResearchAndScholarshipCredentialJwtVcJson ' ], // TODO mivanci from config
158- isEnabled: true ,
159- );
182+ $ client = $ this ->clientEntityFactory ->fromData (
183+ id: $ clientId ,
184+ secret: $ clientSecret ,
185+ name: 'VCI Pre-authorized Code Test Client ' ,
186+ description: 'Test client for VCI Pre-authorized Code ' ,
187+ redirectUri: ['https://example.com/oidc/callback ' ],
188+ scopes: ['openid ' , ...$ credentialConfigurationIdsSupported ], // Test Client so will have
189+ isEnabled: true ,
190+ );
160191
192+ if ($ this ->clientRepository ->findById ($ clientId ) === null ) {
161193 $ this ->clientRepository ->add ($ client );
194+ } else {
195+ $ this ->clientRepository ->update ($ client );
162196 }
197+
198+ // TODO mivanci Randomly generate auth code.
163199 $ authCodeId = '1234567890 ' ;
164200
165201 // TODO mivanci Add indication of preauthz code to the auth code table.
@@ -170,7 +206,7 @@ public function verifiableCredentialIssuance(Request $request): Response
170206 client: $ client ,
171207 scopes: [
172208 new ScopeEntity ('openid ' ),
173- new ScopeEntity (' ResearchAndScholarshipCredentialJwtVcJson ' ),
209+ new ScopeEntity ($ selectedCredentialConfigurationId ),
174210 ],
175211 expiryDateTime: new \DateTimeImmutable ('+1 month ' ),
176212 userIdentifier: $ userId ,
@@ -185,7 +221,7 @@ public function verifiableCredentialIssuance(Request $request): Response
185221 parameters: [
186222 ClaimsEnum::CredentialIssuer->value => $ this ->moduleConfig ->getIssuer (),
187223 ClaimsEnum::CredentialConfigurationIds->value => [
188- ' ResearchAndScholarshipCredentialJwtVcJson ' , // TODO mivanci from config
224+ $ selectedCredentialConfigurationId ,
189225 ],
190226 ClaimsEnum::Grants->value => [
191227 GrantTypesEnum::PreAuthorizedCode->value => [
@@ -210,6 +246,7 @@ public function verifiableCredentialIssuance(Request $request): Response
210246
211247 $ credentialOfferUri = "openid-credential-offer://? $ parameterName= $ credentialOfferValue " ;
212248
249+ // TODO mivanci Local QR code generator
213250 // https://quickchart.io/documentation/qr-codes/
214251 $ credentialOfferQrUri = 'https://quickchart.io/qr?size=200&margin=1&text= ' . urlencode ($ credentialOfferUri );
215252 }
@@ -223,11 +260,14 @@ public function verifiableCredentialIssuance(Request $request): Response
223260 return $ this ->templateFactory ->build (
224261 'oidc:tests/verifiable-credential-issuance.twig ' ,
225262 compact (
263+ 'setupErrors ' ,
226264 'credentialOfferQrUri ' ,
227265 'credentialOfferUri ' ,
228266 'authSourceIds ' ,
229267 'authSourceActionRoute ' ,
230268 'authSource ' ,
269+ 'credentialConfigurationIdsSupported ' ,
270+ 'selectedCredentialConfigurationId '
231271 ),
232272 RoutesEnum::AdminTestVerifiableCredentialIssuance->value ,
233273 );
0 commit comments