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 OAuth2AuthorizationServerMetadata.tokenEndpoint).
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(state, AuthorizationForToken.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 preAuth = credentialOffer.grants.preAuthorizedCode
val transactionCode = "..." // get from user input
val authorization = WalletService.AuthorizationForToken.PreAuthCode(preAuth, transactionCode)
val tokenRequest = client.createTokenRequestParameters(state, authorization)
val tokenResponse = httpClient.submitForm(
url = issuerMetadata.tokenEndpointUrl!!,
formParameters = parameters {
tokenRequest.encodeToParameters().forEach { append(it.key, it.value) }
}
)
val token = TokenResponseParameters.deserialize(tokenResponse.bodyAsText()).getOrThrow()
Be sure to include a DPoP header if OAuth2AuthorizationServerMetadata.dpopSigningAlgValuesSupported is set, see JwsService.buildDPoPHeader.
Parameters
to keep internal state in further requests
for the token endpoint
from RFC 9396 OAuth 2.0 Rich Authorization Requests
in OID4VCI flows the value scope
from IssuerMetadata.supportedCredentialConfigurations
from RFC 8707 Resource Indicators for OAuth 2.0, in OID4VCI flows the value of IssuerMetadata.credentialIssuer