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

requestOptions

which credential in which representation to request

authorization

for the token endpoint


suspend fun createTokenRequestParameters(credential: SupportedCredentialFormat, requestedAttributes: Set<String>? = null, state: String? = null, authorization: WalletService.AuthorizationForToken): TokenRequestParameters(source)

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

credential

which credential from IssuerMetadata.supportedCredentialConfigurations to request

requestedAttributes

attributes that shall be requested explicitly (selective disclosure)

state

used in createAuthRequest, e.g. when using authorization codes

authorization

for the token endpoint