createTokenRequestParameters
Request token with an authorization code, e.g. from createAuthRequest, or pre-auth code.
Send the result as POST parameters (form-encoded) to the server at /token
(or more specific IssuerMetadata.tokenEndpointUrl).
Sample ktor code for authorization code:
val authnRequest = client.createAuthRequest(requestOptions)
val authnResponse = authorizationService.authorize(authnRequest).getOrThrow()
val code = authnResponse.params.code
val tokenRequest = client.createTokenRequestParameters(requestOptions, code = code)
val tokenResponse = httpClient.submitForm(
url = issuerMetadata.tokenEndpointUrl!!,
formParameters = parameters {
tokenRequest.encodeToParameters().forEach { append(it.key, it.value) }
}
)
val token = TokenResponseParameters.deserialize(tokenResponse.bodyAsText()).getOrThrow()
Sample ktor code for pre-authn code:
val tokenRequest =
client.createTokenRequestParameters(requestOptions, credentialOffer.grants!!.preAuthorizedCode)
val tokenResponse = httpClient.submitForm(
url = issuerMetadata.tokenEndpointUrl!!,
formParameters = parameters {
tokenRequest.encodeToParameters().forEach { append(it.key, it.value) }
}
)
val token = TokenResponseParameters.deserialize(tokenResponse.bodyAsText()).getOrThrow()
Parameters
which credential in which representation to request
for the token endpoint
Request token with an authorization code, e.g. from createAuthRequest, or pre-auth code.
Send the result as POST parameters (form-encoded) to the server at /token
(or more specific IssuerMetadata.tokenEndpointUrl).
Sample ktor code for authorization code:
val authnRequest = client.createAuthRequest(requestOptions)
val authnResponse = authorizationService.authorize(authnRequest).getOrThrow()
val code = authnResponse.params.code
val tokenRequest = client.createTokenRequestParameters(requestOptions, code = code)
val tokenResponse = httpClient.submitForm(
url = issuerMetadata.tokenEndpointUrl!!,
formParameters = parameters {
tokenRequest.encodeToParameters().forEach { append(it.key, it.value) }
}
)
val token = TokenResponseParameters.deserialize(tokenResponse.bodyAsText()).getOrThrow()
Sample ktor code for pre-authn code:
val tokenRequest =
client.createTokenRequestParameters(requestOptions, credentialOffer.grants!!.preAuthorizedCode)
val tokenResponse = httpClient.submitForm(
url = issuerMetadata.tokenEndpointUrl!!,
formParameters = parameters {
tokenRequest.encodeToParameters().forEach { append(it.key, it.value) }
}
)
val token = TokenResponseParameters.deserialize(tokenResponse.bodyAsText()).getOrThrow()
Parameters
which credential from IssuerMetadata.supportedCredentialConfigurations to request
attributes that shall be requested explicitly (selective disclosure)
used in createAuthRequest, e.g. when using authorization codes
for the token endpoint