44
55namespace SimpleSAML \Module \oidc \Controllers \Admin ;
66
7- use DateTimeImmutable ;
87use SimpleSAML \Auth \Simple ;
98use SimpleSAML \Module \oidc \Admin \Authorization ;
109use SimpleSAML \Module \oidc \Bridges \SspBridge ;
11- use SimpleSAML \Module \oidc \Codebooks \ParametersEnum ;
1210use SimpleSAML \Module \oidc \Codebooks \RoutesEnum ;
13- use SimpleSAML \Module \oidc \Entities \ScopeEntity ;
1411use SimpleSAML \Module \oidc \Factories \AuthSimpleFactory ;
12+ use SimpleSAML \Module \oidc \Factories \CredentialOfferUriFactory ;
1513use SimpleSAML \Module \oidc \Factories \EmailFactory ;
1614use SimpleSAML \Module \oidc \Factories \Entities \AuthCodeEntityFactory ;
1715use SimpleSAML \Module \oidc \Factories \Entities \ClientEntityFactory ;
2624use SimpleSAML \Module \oidc \Services \SessionService ;
2725use SimpleSAML \Module \oidc \Utils \ProtocolCache ;
2826use SimpleSAML \Module \oidc \Utils \Routes ;
29- use SimpleSAML \OpenID \Codebooks \ClaimsEnum ;
30- use SimpleSAML \OpenID \Codebooks \GrantTypesEnum ;
3127use SimpleSAML \OpenID \VerifiableCredentials ;
3228use Symfony \Component \HttpFoundation \Request ;
3329use Symfony \Component \HttpFoundation \Response ;
@@ -38,21 +34,13 @@ public function __construct(
3834 protected readonly ModuleConfig $ moduleConfig ,
3935 protected readonly TemplateFactory $ templateFactory ,
4036 protected readonly Authorization $ authorization ,
41- protected readonly VerifiableCredentials $ verifiableCredentials ,
42- protected readonly AuthCodeRepository $ authCodeRepository ,
43- protected readonly AuthCodeEntityFactory $ authCodeEntityFactory ,
44- protected readonly ClientRepository $ clientRepository ,
45- protected readonly ClientEntityFactory $ clientEntityFactory ,
4637 protected readonly LoggerService $ loggerService ,
4738 protected readonly EmailFactory $ emailFactory ,
48- protected readonly ?ProtocolCache $ protocolCache ,
49- protected readonly SessionMessagesService $ sessionMessagesService ,
5039 protected readonly AuthSimpleFactory $ authSimpleFactory ,
5140 protected readonly SessionService $ sessionService ,
5241 protected readonly SspBridge $ sspBridge ,
5342 protected readonly Routes $ routes ,
54- protected readonly UserRepository $ userRepository ,
55- protected readonly UserEntityFactory $ userEntityFactory ,
43+ protected readonly CredentialOfferUriFactory $ credentialOfferUriFactory ,
5644 ) {
5745 $ this ->authorization ->requireAdmin (true );
5846 }
@@ -142,79 +130,11 @@ public function verifiableCredentialIssuance(Request $request): Response
142130 ) {
143131 $ userAttributes = $ authSource ->getAttributes ();
144132
145- $ userId = $ this ->sspBridge ->utils ()->attributes ()->getExpectedAttribute (
133+ $ credentialOfferUri = $ this ->credentialOfferUriFactory ->buildPreAuthorized (
134+ [$ selectedCredentialConfigurationId ],
146135 $ userAttributes ,
147- $ this ->moduleConfig ->getUserIdentifierAttribute (),
148136 );
149137
150- // Persist / update user entity.
151- $ userEntity = $ this ->userRepository ->getUserEntityByIdentifier ($ userId );
152-
153- if ($ userEntity ) {
154- $ userEntity ->setClaims ($ userAttributes );
155- $ this ->userRepository ->update ($ userEntity );
156- } else {
157- $ userEntity = $ this ->userEntityFactory ->fromData ($ userId , $ userAttributes );
158- $ this ->userRepository ->add ($ userEntity );
159- }
160-
161- /* TODO mivanci TX Code handling
162- $email = $this->emailFactory->build(
163- subject: 'VC Issuance Transaction code',
164- 165- );
166-
167- $email->setData(['Transaction Code' => '1234']);
168- try {
169- $email->send();
170- $this->sessionMessagesService->addMessage('Email with tx code sent to: [email protected] '); 171- } catch (Exception $e) {
172- $this->sessionMessagesService->addMessage('Error emailing tx code.');
173- }
174- */
175-
176- // TODO mivanci Wallet (client) credential_offer_endpoint metadata
177- // https://openid.net/specs/openid-4-verifiable-credential-issuance-1_0.html#client-metadata
178-
179-
180- $ client = $ this ->clientEntityFactory ->getGenericForVciPreAuthZFlow ();
181- if ($ this ->clientRepository ->findById ($ client ->getIdentifier ()) === null ) {
182- $ this ->clientRepository ->add ($ client );
183- } else {
184- $ this ->clientRepository ->update ($ client );
185- }
186-
187-
188-
189- $ credentialOffer = $ this ->verifiableCredentials ->credentialOfferFactory ()->from (
190- parameters: [
191- ClaimsEnum::CredentialIssuer->value => $ this ->moduleConfig ->getIssuer (),
192- ClaimsEnum::CredentialConfigurationIds->value => [
193- $ selectedCredentialConfigurationId ,
194- ],
195- ClaimsEnum::Grants->value => [
196- GrantTypesEnum::PreAuthorizedCode->value => [
197- ClaimsEnum::PreAuthorizedCode->value => $ authCode ->getIdentifier (),
198- // TODO mivanci support for TxCode
199- // ClaimsEnum::TxCode->value => [
200- // ClaimsEnum::InputMode->value => 'numeric',
201- // ClaimsEnum::Length->value => 6,
202- // ClaimsEnum::Description->value => 'Sent to user mail',
203- // ],
204- ],
205- ],
206- ],
207- );
208-
209- $ credentialOfferValue = $ credentialOffer ->jsonSerialize ();
210- $ parameterName = ParametersEnum::CredentialOfferUri->value ;
211- if (is_array ($ credentialOfferValue )) {
212- $ parameterName = ParametersEnum::CredentialOffer->value ;
213- $ credentialOfferValue = json_encode ($ credentialOfferValue );
214- }
215-
216- $ credentialOfferUri = "openid-credential-offer://? $ parameterName= $ credentialOfferValue " ;
217-
218138 // TODO mivanci Local QR code generator
219139 // https://quickchart.io/documentation/qr-codes/
220140 $ credentialOfferQrUri = 'https://quickchart.io/qr?size=200&margin=1&text= ' . urlencode ($ credentialOfferUri );
0 commit comments