-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Talwinder Kaur <[email protected]>
- Loading branch information
1 parent
936b08f
commit 598a230
Showing
6 changed files
with
176 additions
and
296 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -170,123 +170,4 @@ class IntegrationTest { | |
"registration", """{"email":"[email protected]"}""").addScopeClaim("testscope", """{"data": "testdata"}""") | ||
.setAttestationVC(userDID.assertionMethod(), attestationVC.serialize())) | ||
} | ||
|
||
@Test | ||
fun testAuthFlow() { | ||
val trace = Otel.newTrace() | ||
|
||
assertThat(Version.getVersion()).isEqualTo("testVer") | ||
assertThat(Version.getGitRevision()).isEqualTo("testRev") | ||
assertThat(Version.getBuildTime()).isEqualTo("testTime") | ||
|
||
val kms = Localkms.newKMS(KmsStore(instrumentationContext)) | ||
|
||
val resolverOpts = ResolverOpts() | ||
resolverOpts.setResolverServerURI("http://localhost:8072/1.0/identifiers") | ||
val didResolver = Resolver(resolverOpts) | ||
|
||
val crypto = kms.crypto | ||
|
||
val jwk = kms.create(Localkms.KeyTypeED25519) | ||
|
||
val userDID = Didion.createLongForm(jwk) | ||
|
||
// Issue VCs | ||
val requestURI = BuildConfig.INITIATE_ISSUANCE_URLS_AUTH_CODE_FLOW | ||
println("requestURI ->") | ||
println(requestURI) | ||
|
||
val requiredOpenID4CIArgs = IssuerInitiatedInteractionArgs(requestURI, crypto, didResolver) | ||
println("requiredOpenID4CIArgs") | ||
println(requiredOpenID4CIArgs) | ||
val ciOpts = InteractionOpts() | ||
ciOpts.addHeader(trace.traceHeader()) | ||
|
||
val ciInteraction = IssuerInitiatedInteraction(requiredOpenID4CIArgs, ciOpts) | ||
var clientID = "oidc4vc_client" | ||
val redirectURI = "http://127.0.0.1/callback" | ||
var scopes = StringArray() | ||
scopes.append("openid").append("profile") | ||
|
||
assertThat(ciInteraction.dynamicClientRegistrationSupported()).isTrue() | ||
|
||
if (ciInteraction.dynamicClientRegistrationSupported()) { | ||
var dynamicRegistrationEndpoint = ciInteraction.dynamicClientRegistrationEndpoint() | ||
assertThat(dynamicRegistrationEndpoint).isNotEmpty() | ||
|
||
var clientMetadata = Oauth2.newClientMetadata() | ||
var grantTypesArr = StringArray() | ||
grantTypesArr.append("authorization_code") | ||
clientMetadata.setGrantTypes(grantTypesArr) | ||
assertThat(clientMetadata.grantTypes()).isNotNull() | ||
|
||
var redirectUri = StringArray() | ||
redirectUri.append(redirectURI) | ||
clientMetadata.setRedirectURIs(redirectUri) | ||
assertThat(clientMetadata.redirectURIs()).isNotNull() | ||
|
||
clientMetadata.setScopes(scopes) | ||
clientMetadata.setTokenEndpointAuthMethod("none") | ||
|
||
var authorizationCodeGrantParams = ciInteraction.authorizationCodeGrantParams() | ||
if (authorizationCodeGrantParams.hasIssuerState()) { | ||
var issuerState = authorizationCodeGrantParams.issuerState() | ||
clientMetadata.setIssuerState(issuerState) | ||
assertThat(clientMetadata.issuerState()).isNotEmpty() | ||
} | ||
|
||
var registrationResp = Oauth2.registerClient(dynamicRegistrationEndpoint, clientMetadata, null) | ||
clientID = registrationResp.clientID() | ||
assertThat(clientID).isNotEmpty() | ||
|
||
scopes = registrationResp.registeredMetadata().scopes() | ||
assertThat(scopes).isNotNull() | ||
} | ||
|
||
val authCodeGrant = ciInteraction.authorizationCodeGrantTypeSupported() | ||
assertThat(authCodeGrant).isTrue() | ||
|
||
val createAuthorizationURLOpts = CreateAuthorizationURLOpts().setScopes(scopes) | ||
|
||
val authorizationLink = ciInteraction.createAuthorizationURL(clientID, redirectURI, createAuthorizationURLOpts) | ||
assertThat(authorizationLink).isNotEmpty() | ||
|
||
var redirectUrl = URI(authorizationLink) | ||
|
||
val client = OkHttpClient.Builder() | ||
.retryOnConnectionFailure(true) | ||
.followRedirects(false) | ||
.build() | ||
|
||
var request = Request.Builder() | ||
.url(redirectUrl.toString()) | ||
.header("Connection", "close") | ||
.build() | ||
val response = client.newCall(request).execute() | ||
assertThat(response.isRedirect).isTrue() | ||
var location = response.headers["Location"] | ||
assertThat(location).contains("cognito-mock.trustbloc.local") | ||
if (location != null) { | ||
if (location.contains("cognito-mock.trustbloc.local")) { | ||
var upr = URI(location.replace("cognito-mock.trustbloc.local", "localhost")); | ||
assertThat(upr.toString()).contains("localhost") | ||
var request = Request.Builder() | ||
.url(upr.toString()) | ||
.header("Connection", "close") | ||
.build() | ||
val response = client.newCall(request).clone().execute() | ||
location = response.headers["location"] | ||
assertThat(location).contains("oidc/redirect") | ||
var request2 = Request.Builder() | ||
.url(location.toString()) | ||
.header("Connection", "close") | ||
.build() | ||
val response2 = client.newCall(request2).clone().execute() | ||
location = response2.headers["location"] | ||
assertThat(location).contains("127.0.0.1") | ||
var issuedCreds = ciInteraction.requestCredentialWithAuth(userDID.assertionMethod(), location, null) | ||
assertThat(issuedCreds.length()).isGreaterThan(0) | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,19 +74,20 @@ void main() async { | |
|
||
print('getSubmissionRequirements finished'); | ||
|
||
expect(requirements, hasLength(equals(1))); | ||
/* expect(requirements, hasLength(equals(1))); | ||
expect(requirements[0].inputDescriptors, hasLength(equals(1))); | ||
expect(requirements[0].inputDescriptors[0].matchedVCsID, hasLength(equals(1))); | ||
expect(requirements[0].inputDescriptors[0].matchedVCsID, hasLength(equals(1)));*/ | ||
var customScopesList = { | ||
'registration': jsonEncode({'email': '[email protected]'}), | ||
}; | ||
|
||
await walletSDKPlugin.presentCredential( | ||
selectedCredentials: credentials, customScopeList: customScopesList, attestationVC: attestationVC); | ||
print('credential presented'); | ||
} | ||
}); | ||
}, timeout: Timeout(Duration(minutes: 20))); | ||
|
||
testWidgets('Testing openid4vc with multiple credentials', (tester) async { | ||
/*testWidgets('Testing openid4vc with multiple credentials', (tester) async { | ||
const didMethodTypes = String.fromEnvironment('WALLET_DID_METHODS'); | ||
var didMethodTypesList = didMethodTypes.split(' '); | ||
String didMethodType = didMethodTypesList[0]; | ||
|
@@ -141,68 +142,5 @@ void main() async { | |
}; | ||
await walletSDKPlugin.presentCredential(selectedCredentials: matchedCreds, customScopeList: customScopesList); | ||
}); | ||
|
||
testWidgets('Testing openid4vc with the auth code flow', (tester) async { | ||
const didMethodTypes = String.fromEnvironment('WALLET_DID_METHODS'); | ||
var didMethodTypesList = didMethodTypes.split(' '); | ||
String didMethodType = didMethodTypesList[0]; | ||
print('wallet DID type : $didMethodType'); | ||
print('wallet DID Key type : $didKeyType'); | ||
var didDocData = await walletSDKPlugin.createDID(didMethodTypesList[0], didKeyType); | ||
print('wallet didDocData : $didDocData'); | ||
var didContent = didDocData.did; | ||
print('wallet DID : $didContent'); | ||
|
||
const issuanceURL = String.fromEnvironment('INITIATE_ISSUANCE_URLS_AUTH_CODE_FLOW'); | ||
debugPrint('issuanceURLs Auth Code Flow: $issuanceURL'); | ||
|
||
var authCodeArgs = { | ||
'scopes': ['openid', 'profile'], | ||
'clientID': 'oidc4vc_client', | ||
'redirectURI': 'http://127.0.0.1/callback' | ||
}; | ||
|
||
var initializeResp = await walletSDKPlugin.initialize(issuanceURL, authCodeArgs); | ||
var initializeRespEncoded = json.encode(initializeResp!); | ||
Map<String, dynamic> initializeRespJson = json.decode(initializeRespEncoded); | ||
var authorizationURLLink = initializeRespJson['authorizationURLLink']; | ||
debugPrint('authorizationURLLink: $authorizationURLLink'); | ||
// fetching redirect uri | ||
String redirectURI = ''; | ||
final client = HttpClient(); | ||
var redirectUrl = Uri.parse(authorizationURLLink); | ||
var request = await client.getUrl(redirectUrl); | ||
request.followRedirects = false; | ||
var response = await request.close(); | ||
while (response.isRedirect) { | ||
response.drain(); | ||
final location = response.headers.value(HttpHeaders.locationHeader); | ||
if (location != null) { | ||
redirectUrl = redirectUrl.resolve(location); | ||
if (location.contains('http://127.0.0.1/callback')) { | ||
redirectURI = location; | ||
break; | ||
} | ||
if (redirectUrl.host.contains('cognito-mock.trustbloc.local')) { | ||
redirectUrl = Uri.parse(redirectUrl.toString().replaceAll('cognito-mock.trustbloc.local', 'localhost')); | ||
print('uri updated $redirectUrl'); | ||
} | ||
request = await client.getUrl(redirectUrl); | ||
request.followRedirects = false; | ||
response = await request.close(); | ||
} | ||
} | ||
|
||
debugPrint('redirectURI $redirectURI'); | ||
|
||
final credential = await walletSDKPlugin.requestCredentialWithAuth(redirectURI); | ||
debugPrint('content: $credential'); | ||
for (final p in credential.split('.')) { | ||
print('----'); | ||
print(p); | ||
} | ||
|
||
expect(credential, hasLength(greaterThan(0))); | ||
}); | ||
} | ||
},timeout: Timeout(Duration(minutes: 20)));*/ | ||
} |
Oops, something went wrong.