Skip to content

Commit

Permalink
integrate impierce oid4vc
Browse files Browse the repository at this point in the history
  • Loading branch information
eike-hass committed May 31, 2024
1 parent 3f16c15 commit a91f24b
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 19 deletions.
86 changes: 75 additions & 11 deletions backend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"dependencies": {
"@grpc/grpc-js": "^1.9.13",
"@grpc/proto-loader": "^0.7.10",
"@nestjs/axios": "^3.0.2",
"@nestjs/cache-manager": "^2.2.0",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.1.1",
Expand All @@ -32,6 +33,7 @@
"@nestjs/platform-socket.io": "^10.3.0",
"@nestjs/serve-static": "^4.0.0",
"@nestjs/websockets": "^10.3.0",
"axios": "^1.7.2",
"cache-manager": "^5.3.2",
"cache-manager-redis-yet": "^4.1.2",
"ioredis": "^5.3.2",
Expand Down
35 changes: 35 additions & 0 deletions backend/src/oid4vc/oid4vc-impierce.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { HttpService } from '@nestjs/axios';
import { Injectable, Logger } from '@nestjs/common';
import { AxiosError } from 'axios';
import { catchError, firstValueFrom } from 'rxjs';
import { SIOPV2RequestConfig } from './siopv2';

@Injectable()
export class OID4VCImpierceService {
private readonly logger = new Logger(OID4VCImpierceService.name);

constructor(private readonly httpService: HttpService) {}

async createSIOPInvite(request: SIOPV2RequestConfig): Promise<string> {
const response = await firstValueFrom(
this.httpService
.post<string>(
'http://oid4vc-impierce:3033/v1/authorization_requests',
{
nonce: 'test', // TODO: remove or replace with proper nonce
state: request.state,
},
{
responseType: 'formdata',
},
)
.pipe(
catchError((error: AxiosError) => {
this.logger.error(error.response.data);
throw 'An error happened!';
}),
),
);
return response.data;
}
}
5 changes: 4 additions & 1 deletion backend/src/oid4vc/oid4vc.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import { OID4VCIService, OID4VPService, SIOPV2Service } from './oid4vc.service';
import { OID4VC_PACKAGE_NAME } from './siopv2';
import { ConfigModule, ConfigService } from '@nestjs/config';
import configuration from './configuration';
import { OID4VCImpierceService } from './oid4vc-impierce.service';
import { HttpModule } from '@nestjs/axios';

@Module({
imports: [ConfigModule.forFeature(configuration)], //TODO: figure out https://docs.nestjs.com/fundamentals/dynamic-modules#config-module-example
imports: [ConfigModule.forFeature(configuration), HttpModule], //TODO: figure out https://docs.nestjs.com/fundamentals/dynamic-modules#config-module-example
controllers: [],
providers: [
SIOPV2Service,
Expand Down Expand Up @@ -41,6 +43,7 @@ import configuration from './configuration';
}),
inject: [ConfigService],
},
OID4VCImpierceService,
],
exports: [SIOPV2Service, OID4VPService, OID4VCIService],
})
Expand Down
7 changes: 5 additions & 2 deletions backend/src/oid4vc/oid4vc.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
OfferConfig,
} from './oid4vci';
import { Providers } from '../../../shared/types/Providers';
import { OID4VCImpierceService } from './oid4vc-impierce.service';

//
// SIOP
Expand All @@ -35,6 +36,7 @@ export class SIOPV2Service implements OnModuleInit {
constructor(
@Inject(OID4VC_PACKAGE_NAME) private client: ClientGrpc,
private configService: ConfigService,
private readonly impierceService: OID4VCImpierceService,
) {}

onModuleInit() {
Expand All @@ -45,7 +47,7 @@ export class SIOPV2Service implements OnModuleInit {

async createSIOPV2Request(
request: SIOPV2RequestConfig & { provider: Providers },
): Promise<SIOPV2Request> {
): Promise<string> {
this.logger.debug('Received createSIOPV2Request request', request);

switch (request.provider) {
Expand All @@ -61,12 +63,13 @@ export class SIOPV2Service implements OnModuleInit {
),
);
this.logger.debug('build request', buildRequest);
return buildRequest;
return buildRequest.uri;
} catch (error) {
this.logger.error(error);
throw error;
}
case Providers.Impierce:
return await this.impierceService.createSIOPInvite(request);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion backend/src/webapp/webapp.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export class WebAppService {
provider,
});

return siopResponse.uri;
return siopResponse;
}

async requestPresentation(
Expand Down
4 changes: 2 additions & 2 deletions tooling/API/Backend/GRPC.http
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ proto < ../../../shared/proto/user/user.proto
GRPC /UsersService/ConnectUser
{
"did": "did:key:z6MkfDvsiwx8ddaUitBuwxn8fCfyMZkK7ipQanMVS1FqvchE",
"code": "a4e4aadf-90c7-4112-b00d-edb09496fc6e"
"code": "3c9323c8-8691-4fb4-b406-43113592010d"
}
###
{{
Expand Down Expand Up @@ -81,7 +81,7 @@ GRPC /UsersService/RequestCredential
{
"user": {
"did": "did:key:z6MkfDvsiwx8ddaUitBuwxn8fCfyMZkK7ipQanMVS1FqvchE",
"code": "063bf112-5e45-4529-a085-fd91c79d8837"
"code": "ae794ad5-7c88-4397-abb9-e5e0771aa97a"
},
"credentialDefinition": {
"type": [ "VerifiableCredential", "CitizenCredential" ]
Expand Down
4 changes: 2 additions & 2 deletions tooling/API/OID4VC/Impierce/HTTP.http
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@host=http://insurance.selv.iota.org
@host=http://insurance.selv.local:81
###
POST /v1/credentials
###
Expand All @@ -17,4 +17,4 @@ GET /v1/authorization_requests/06adfc99a128b078726c9cca383df3883db1e8dbd0270518b
POST /redirect
Content-Type: application/x-www-form-urlencoded

id_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJFZERTQSIsImtpZCI6ImRpZDppb3RhOnJtczoweGY4MGM1MTM0OGNmMzIzOGRmMTEzMzE1NmM3ODk2NWQxZDVmOWFiYTJiZjA3MGMyM2ZiYmI5NmVkYjMzNmUxNTQjbVpYbTltSndqN2Q2WHJtejIxS3VvRDA3ZXhvM0lTOVlWWXFwTlk1RjhYSSJ9
id_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJFZERTQSIsImtpZCI6ImRpZDppb3Rh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