Skip to content

Instantly share code, notes, and snippets.

@kevinjom
Last active February 13, 2019 08:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinjom/2c715e4ee5033c0a4c7b152002dcbf82 to your computer and use it in GitHub Desktop.
Save kevinjom/2c715e4ee5033c0a4c7b152002dcbf82 to your computer and use it in GitHub Desktop.
TDD workshop - Simplified OAuth2 Token endpoint

TDD workshop - Simplified OAuth2 Token endpoint

Simple implementation of Okta oauth2 /token endpoint. See https://developer.okta.com/docs/api/resources/oidc#token for the original api reference.

This endpoint only supports authorization_code grant type, and will only return the access_token in the response.

API spec

URL

POST ${baseUrl}/v1/token

Request params

Parameter Description Type
code Required, is what was returned from the authorization endpoint. The code has a lifetime of 60 seconds. String
client_id Required String
client_secret Required, This client secret is used in conjunction with client_id to authenticate the client application.
grant_type Required, Can only be authorization_code. String

Response

Property Description Type
access_token An access token. length of 11, starting with tdd String

List of Errors

Error Id Details
invalid_client (401) The specified client id wasn’t found.
invalid_grant (401) The code, refresh_token, or username and password combination is invalid, or the redirect_uri does not match the one used in the authorization request.
invalid_request (400) The request structure was invalid.eg, mandatory fields are not passed, etc
unsupported_grant_type (400) The grant_type isn’t authorization_code

Response Example (Success)

{
    "access_token" : "tddc567aed3"
}

Response Example (Error)

HTTP 401 Unauthorized
Content-Type: application/json;charset=UTF-8
{
    "error" : "invalid_client",
    "error_description" : "No client credentials found."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment