Skip to content

Commit

Permalink
feat: Add authorized process
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Sep 6, 2023
1 parent b61aa48 commit 1970caf
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 136 deletions.
3 changes: 2 additions & 1 deletion lib/app/shared/constants/parameters.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ class Parameters {
isWalletIntegrityEnabled: true,
);

static const ebsiUniversalLink = 'https://app.altme.io/app/download/ebsi';
static const oidc4vcUniversalLink =
'https://app.altme.io/app/download/oidc4vc/';

static const web3RpcMainnetUrl = 'https://mainnet.infura.io/v3/';

Expand Down
13 changes: 9 additions & 4 deletions lib/app/shared/helper_functions/helper_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,15 @@ Future<(String?, String)> getIssuerAndPreAuthorizedCode({
);
if (credentialOfferJson == null) throw Exception();

preAuthorizedCode = credentialOfferJson['grants']
['urn:ietf:params:oauth:grant-type:pre-authorized_code']
['pre-authorized_code']
.toString();
final dynamic preAuthorizedCodeGrant = credentialOfferJson['grants']
['urn:ietf:params:oauth:grant-type:pre-authorized_code'];

if (preAuthorizedCodeGrant != null &&
preAuthorizedCodeGrant is Map &&
preAuthorizedCodeGrant.containsKey('authorized_code')) {
preAuthorizedCode = preAuthorizedCodeGrant['authorized_code'] as String;
}

issuer = credentialOfferJson['credential_issuer'].toString();

case OIDC4VCType.GAIAX:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,11 @@ class Oidc4vcCredentialPickView extends StatelessWidget {
: () {
if (state.isEmpty) return;

final selectedCredentials =
state.map((index) => credentials[index]).toList();

context.read<QRCodeScanCubit>().addCredentialsInLoop(
credentials: credentials,
credentials: selectedCredentials,
userPin: userPin,
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
required OIDC4VCType currentOIIDC4VCType,
required QRCodeScanCubit qrCodeScanCubit,
}) async {
emit(state.copyWith(uri: Uri.parse(scannedResponse)));
switch (currentOIIDC4VCType) {
case OIDC4VCType.DEFAULT:
case OIDC4VCType.GREENCYPHER:
Expand Down
19 changes: 13 additions & 6 deletions lib/oidc4vc/initiate_oidv4vc_credential_issuance.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ Future<void> getAndAddCredential({
required DioClient dioClient,
required String? userPin,
}) async {
final Uri uriFromScannedResponse = Uri.parse(scannedResponse);

final (preAuthorizedCode, issuer) = await getIssuerAndPreAuthorizedCode(
oidc4vcType: oidc4vcType,
scannedResponse: scannedResponse,
Expand All @@ -102,7 +100,10 @@ Future<void> getAndAddCredential({
didKitProvider: didKitProvider,
);

if (preAuthorizedCode != null) {
final codeForAuthorisedFlow =
Uri.parse(scannedResponse).queryParameters['code'];

if (preAuthorizedCode != null || codeForAuthorisedFlow != null) {
final (
dynamic encodedCredentialOrFutureToken,
String? deferredCredentialEndpoint,
Expand All @@ -113,10 +114,10 @@ Future<void> getAndAddCredential({
credential: credential,
did: did,
kid: kid,
credentialRequestUri: uriFromScannedResponse,
privateKey: privateKey,
indexValue: oidc4vcType.indexValue,
userPin: userPin,
code: codeForAuthorisedFlow,
);
final String credentialName = getCredentialData(credential);
final acceptanceToken = encodedCredentialOrFutureToken['acceptance_token'];
Expand Down Expand Up @@ -177,10 +178,16 @@ Future<void> getAndAddCredential({
);
}
} else {
final dynamic credentialOfferJson = await getCredentialOfferJson(
scannedResponse: scannedResponse,
dioClient: dioClient,
);

final Uri ebsiAuthenticationUri =
await oidc4vc.getAuthorizationUriForIssuer(
scannedResponse,
Parameters.ebsiUniversalLink,
credentialOfferJson: credentialOfferJson,
clientId: did,
redirectUrl: '${Parameters.oidc4vcUniversalLink}$scannedResponse',
);
await LaunchUrl.launchUri(ebsiAuthenticationUri);
}
Expand Down
24 changes: 24 additions & 0 deletions lib/splash/view/splash_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,30 @@ class _SplashViewState extends State<SplashView> {
return;
}

if (uri.toString().startsWith(Parameters.oidc4vcUniversalLink)) {
final url = uri.toString().split(Parameters.oidc4vcUniversalLink)[1];

final List<String> parts = url.split('?');

final String modifiedUrl = '${parts[0]}?${parts.sublist(1).join('&')}';

final OIDC4VCType? currentOIIDC4VCTypeForIssuance =
getOIDC4VCTypeForIssuance(modifiedUrl);

if (currentOIIDC4VCTypeForIssuance != null) {
/// issuer side (oidc4VCI)
await context.read<QRCodeScanCubit>().startOIDC4VCCredentialIssuance(
scannedResponse: modifiedUrl,
currentOIIDC4VCType: currentOIIDC4VCTypeForIssuance,
qrCodeScanCubit: context.read<QRCodeScanCubit>(),
);
return;
}

return;
}

if (uri.toString().startsWith('iden3comm://')) {
/// if wallet has not been created then alert user
final ssiKey =
Expand Down
Loading

0 comments on commit 1970caf

Please sign in to comment.