-
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 5313a9a
Showing
8 changed files
with
172 additions
and
293 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
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
Oops, something went wrong.