1818use SimpleSAML \OpenID \Codebooks \AtContextsEnum ;
1919use SimpleSAML \OpenID \Codebooks \ClaimsEnum ;
2020use SimpleSAML \OpenID \Codebooks \CredentialTypesEnum ;
21+ use SimpleSAML \OpenID \Codebooks \HttpMethodsEnum ;
2122use SimpleSAML \OpenID \Jwk ;
2223use SimpleSAML \OpenID \VerifiableCredentials ;
2324use Symfony \Component \HttpFoundation \Request ;
@@ -53,21 +54,25 @@ public function __construct(
5354 */
5455 public function credential (Request $ request ): Response
5556 {
56- $ this ->loggerService ->info (
57- 'Credential request data: ' ,
58- $ this ->requestParamsResolver ->getAllFromRequest (
59- $ this ->psrHttpBridge ->getPsrHttpFactory ()->createRequest ($ request ),
60- ),
57+ $ requestData = $ this ->requestParamsResolver ->getAllFromRequestBasedOnAllowedMethods (
58+ $ this ->psrHttpBridge ->getPsrHttpFactory ()->createRequest ($ request ),
59+ [HttpMethodsEnum::POST ],
6160 );
6261
62+ $ this ->loggerService ->debug ('Verifiable Credential request data: ' , $ requestData );
63+
6364 $ authorization = $ this ->resourceServer ->validateAuthenticatedRequest (
6465 $ this ->psrHttpBridge ->getPsrHttpFactory ()->createRequest ($ request ),
6566 );
6667
6768 // TODO mivanci validate access token
6869 $ accessToken = $ this ->accessTokenRepository ->findById ($ authorization ->getAttribute ('oauth_access_token_id ' ));
6970 if ($ accessToken ->isRevoked ()) {
70- throw OidcServerException::accessDenied ('Access token is revoked. ' );
71+ return $ this ->routes ->newJsonErrorResponse (
72+ 'invalid_token ' ,
73+ 'Access token is revoked. ' ,
74+ 401 ,
75+ );
7176 }
7277
7378 // TODO mivanci validate credential request, including proof. Sample:
@@ -89,6 +94,35 @@ public function credential(Request $request): Response
8994 * )
9095 */
9196
97+ // TODO mivanci Check / handle credential_identifier parameter.
98+
99+ $ credentialConfigurationId = $ requestData [ClaimsEnum::CredentialConfigurationId->value ] ?? null ;
100+
101+ if (is_null ($ credentialConfigurationId )) {
102+ // Check per draft 14
103+ if (is_array (
104+ $ credentialDefinitionType =
105+ $ requestData [ClaimsEnum::CredentialDefinition->value ][ClaimsEnum::Type->value ],
106+ )
107+ ) {
108+ $ credentialConfigurationId =
109+ $ this ->moduleConfig ->getCredentialConfigurationIdForCredentialDefinitionType (
110+ $ credentialDefinitionType ,
111+ );
112+ }
113+ }
114+
115+ if (is_null ($ credentialConfigurationId )) {
116+ return $ this ->routes ->newJsonErrorResponse ('invalid_credential_request ' , 'Can not resolve credential configuration ID. ' );
117+ }
118+
119+ if (!in_array ($ credentialConfigurationId , $ this ->moduleConfig ->getCredentialConfigurationIdsSupported ())) {
120+ return $ this ->routes ->newJsonErrorResponse (
121+ 'unsupported_credential_type ' ,
122+ sprintf ('Credential configuration ID "%s" is not supported. ' , $ credentialConfigurationId ),
123+ );
124+ }
125+
92126 $ userId = $ accessToken ->getUserIdentifier ();
93127 $ userEntity = $ this ->userRepository ->getUserEntityByIdentifier ($ userId );
94128 if ($ userEntity === null ) {
@@ -97,10 +131,6 @@ public function credential(Request $request): Response
97131
98132 $ userAttributes = $ userEntity ->getClaims ();
99133
100- // TODO mivanci Resolve credential configuration ID from the credential request. Validate that the credential
101- // configuration ID is supported (check module configuration).
102- $ credentialConfigurationId = 'ResearchAndScholarshipCredentialJwtVcJson ' ;
103-
104134 // Get valid claim paths so we can check if the user attribute is allowed to be included in the credential,
105135 // as per the credential configuration supported configuration.
106136 $ validClaimPaths = $ this ->moduleConfig ->getValidCredentialClaimPathsFor ($ credentialConfigurationId );
@@ -156,7 +186,7 @@ public function credential(Request $request): Response
156186 ],
157187 ClaimsEnum::Type->value => [
158188 CredentialTypesEnum::VerifiableCredential->value ,
159- ' ResearchAndScholarshipCredentialJwtVcJson ' ,
189+ $ credentialConfigurationId ,
160190 ],
161191 //ClaimsEnum::Issuer->value => $this->moduleConfig->getIssuer(),
162192 ClaimsEnum::Issuer->value => $ issuerDid ,
0 commit comments