Skip to content

Commit

Permalink
feat: Use different auth for draft 13 and avbove with exception #3021
Browse files Browse the repository at this point in the history
  • Loading branch information
bibash28 committed Oct 29, 2024
1 parent 1f7d161 commit 96a1f77
Show file tree
Hide file tree
Showing 11 changed files with 89 additions and 31 deletions.
24 changes: 24 additions & 0 deletions lib/app/shared/helper_functions/helper_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ Future<
required DioClient client,
required OIDC4VC oidc4vc,
required OIDC4VCIDraftType oidc4vciDraftType,
required bool useOAuthAuthorizationServerLink,
}) async {
final uri = Uri.parse(url);

Expand Down Expand Up @@ -729,6 +730,7 @@ Future<
baseUrl: issuer,
isAuthorizationServer: false,
dio: client.dio,
useOAuthAuthorizationServerLink: useOAuthAuthorizationServerLink,
);

if (preAuthorizedCode == null) {
Expand All @@ -754,6 +756,7 @@ Future<
baseUrl: authorizationServer,
isAuthorizationServer: true,
dio: client.dio,
useOAuthAuthorizationServerLink: useOAuthAuthorizationServerLink,
);
}

Expand Down Expand Up @@ -996,6 +999,7 @@ Future<bool?> isEBSIForVerifiers({
required Uri uri,
required OIDC4VC oidc4vc,
required OIDC4VCIDraftType oidc4vciDraftType,
required bool useOAuthAuthorizationServerLink,
}) async {
try {
final String? clientId = uri.queryParameters['client_id'];
Expand All @@ -1010,6 +1014,7 @@ Future<bool?> isEBSIForVerifiers({
baseUrl: clientId,
isAuthorizationServer: false,
dio: Dio(),
useOAuthAuthorizationServerLink: useOAuthAuthorizationServerLink,
);

final subjectTrustFrameworksSupported =
Expand Down Expand Up @@ -2193,3 +2198,22 @@ String getDidMethod(BlockchainType blockchainType) {

return didMethod;
}

bool useOauthServerAuthEndPoint(ProfileModel profileModel) {
final profileSetting = profileModel.profileSetting;
final customOidc4vcProfile =
profileSetting.selfSovereignIdentityOptions.customOidc4vcProfile;

final bool notEligible = profileModel.profileType == ProfileType.ebsiV3 ||
profileModel.profileType == ProfileType.ebsiV4 ||
profileModel.profileType == ProfileType.defaultOne;

if (notEligible) return false;

final bool greaterThanDraft13 =
customOidc4vcProfile.oidc4vciDraft != OIDC4VCIDraftType.draft11;

if (greaterThanDraft13) return true;

return false;
}
2 changes: 2 additions & 0 deletions lib/dashboard/home/home/cubit/home_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ class HomeCubit extends Cubit<HomeState> {
await getCredentialManifestFromAltMe(
oidc4vc: oidc4vc,
oidc4vciDraftType: oidc4vciDraftType,
useOAuthAuthorizationServerLink:
useOauthServerAuthEndPoint(profileCubit.state.model),
);
credentialManifest.outputDescriptors?.removeWhere(
(element) => element.id != credentialSubjectType.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ class CredentialDetailsCubit extends Cubit<CredentialDetailsState> {
jwt: response.toString(),
fromStatusList: true,
isCachingEnabled: customOidc4vcProfile.statusListCache,
useOAuthAuthorizationServerLink:
useOauthServerAuthEndPoint(profileCubit.state.model),
);

if (isVerified != VerificationType.verified) {
Expand Down Expand Up @@ -254,6 +256,8 @@ class CredentialDetailsCubit extends Cubit<CredentialDetailsState> {
jwt: response.toString(),
fromStatusList: true,
isCachingEnabled: customOidc4vcProfile.statusListCache,
useOAuthAuthorizationServerLink:
useOauthServerAuthEndPoint(profileCubit.state.model),
);

if (isVerified != VerificationType.verified) {
Expand Down Expand Up @@ -333,6 +337,8 @@ class CredentialDetailsCubit extends Cubit<CredentialDetailsState> {
jwtDecode: jwtDecode,
jwt: jwt,
publicKeyJwk: publicKeyJwk,
useOAuthAuthorizationServerLink:
useOauthServerAuthEndPoint(profileCubit.state.model),
);

if (isVerified == VerificationType.verified) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@ import 'package:oidc4vc/oidc4vc.dart';
Future<CredentialManifest> getCredentialManifestFromAltMe({
required OIDC4VC oidc4vc,
required OIDC4VCIDraftType oidc4vciDraftType,
required bool useOAuthAuthorizationServerLink,
}) async {
final OpenIdConfiguration openIdConfiguration = await oidc4vc.getOpenIdConfig(
baseUrl: 'https://issuer.talao.co',
isAuthorizationServer: false,
dio: Dio(),
useOAuthAuthorizationServerLink: useOAuthAuthorizationServerLink,
);
final JsonPath credentialManifetPath = JsonPath(r'$..credential_manifest');
final credentialManifest = CredentialManifest.fromJson(
Expand Down
10 changes: 10 additions & 0 deletions lib/dashboard/qr_code/qr_code_scan/cubit/qr_code_scan_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -831,6 +831,8 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
client: client,
oidc4vc: oidc4vc,
oidc4vciDraftType: customOidc4vcProfile.oidc4vciDraft,
useOAuthAuthorizationServerLink:
useOauthServerAuthEndPoint(profileCubit.state.model),
);

if (openIdConfiguration != null) {
Expand Down Expand Up @@ -1153,6 +1155,8 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
jwtDecode: jwtDecode,
jwt: encodedData,
publicKeyJwk: publicKeyJwk,
useOAuthAuthorizationServerLink:
useOauthServerAuthEndPoint(profileCubit.state.model),
);

if (isVerified != VerificationType.verified) {
Expand Down Expand Up @@ -1320,6 +1324,8 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
client: client,
profileType: profileCubit.state.model.profileType,
walletIssuer: Parameters.walletIssuer,
useOAuthAuthorizationServerLink:
useOauthServerAuthEndPoint(profileCubit.state.model),
);
goBack();
}
Expand Down Expand Up @@ -1369,6 +1375,8 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
baseUrl: issuer,
isAuthorizationServer: false,
dio: client.dio,
useOAuthAuthorizationServerLink:
useOauthServerAuthEndPoint(profileCubit.state.model),
);

if (savedAccessToken == null) {
Expand All @@ -1393,6 +1401,8 @@ class QRCodeScanCubit extends Cubit<QRCodeScanState> {
oAuthClientAttestation: oAuthClientAttestation,
oAuthClientAttestationPop: oAuthClientAttestationPop,
dio: client.dio,
useOAuthAuthorizationServerLink:
useOauthServerAuthEndPoint(profileCubit.state.model),
);

savedAccessToken = accessToken;
Expand Down
4 changes: 4 additions & 0 deletions lib/enterprise/cubit/enterprise_cubit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ class EnterpriseCubit extends Cubit<EnterpriseState> {
issuer: did,
jwtDecode: profileCubit.jwtDecode,
jwt: jwtVc,
useOAuthAuthorizationServerLink:
useOauthServerAuthEndPoint(profileCubit.state.model),
);

if (isVerified != VerificationType.verified) {
Expand Down Expand Up @@ -340,6 +342,8 @@ class EnterpriseCubit extends Cubit<EnterpriseState> {
jwtDecode: profileCubit.jwtDecode,
jwt: response.toString(),
fromStatusList: true,
useOAuthAuthorizationServerLink:
useOauthServerAuthEndPoint(profileCubit.state.model),
);

if (isVerified != VerificationType.verified) {
Expand Down
2 changes: 2 additions & 0 deletions lib/oidc4vc/get_authorization_uri_for_issuer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Future<void> getAuthorizationUriForIssuer({
required DioClient client,
required ProfileType profileType,
required String walletIssuer,
required bool useOAuthAuthorizationServerLink,
}) async {
/// this is first phase flow for authorization_code
Expand Down Expand Up @@ -109,6 +110,7 @@ Future<void> getAuthorizationUriForIssuer({
isEBSIProfile:
profileType == ProfileType.ebsiV3 || profileType == ProfileType.ebsiV4,
walletIssuer: walletIssuer,
useOAuthAuthorizationServerLink: useOAuthAuthorizationServerLink,
);

final requirePushedAuthorizationRequests =
Expand Down
2 changes: 2 additions & 0 deletions lib/oidc4vc/verify_encoded_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Future<VerificationType> verifyEncodedData({
required String issuer,
required JWTDecode jwtDecode,
required String jwt,
required bool useOAuthAuthorizationServerLink,
Map<String, dynamic>? publicKeyJwk,
bool fromStatusList = false,
bool isCachingEnabled = false,
Expand Down Expand Up @@ -36,6 +37,7 @@ Future<VerificationType> verifyEncodedData({
fromStatusList: fromStatusList,
isCachingEnabled: isCachingEnabled,
dio: Dio(),
useOAuthAuthorizationServerLink: useOAuthAuthorizationServerLink,
);
return verificationType;
}
4 changes: 4 additions & 0 deletions lib/splash/bloclisteners/blocklisteners.dart
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,8 @@ final qrCodeBlocListener = BlocListener<QRCodeScanCubit, QRCodeScanState>(
oidc4vc: oidc4vc,
oidc4vciDraftType: profileSetting.selfSovereignIdentityOptions
.customOidc4vcProfile.oidc4vciDraft,
useOAuthAuthorizationServerLink:
useOauthServerAuthEndPoint(profileCubit.state.model),
);

oidc4vcTypeForIssuance = oidc4vcType;
Expand All @@ -279,6 +281,8 @@ final qrCodeBlocListener = BlocListener<QRCodeScanCubit, QRCodeScanState>(
issuer: issuer,
oidc4vciDraftType: customOidc4vcProfile.oidc4vciDraft,
dio: Dio(),
useOAuthAuthorizationServerLink:
useOauthServerAuthEndPoint(profileCubit.state.model),
);

credentialEndpoint =
Expand Down
Loading

0 comments on commit 96a1f77

Please sign in to comment.