FusionAuth.JWT (FusionAuth v0.3.0) View Source
The FusionAuth.JWT
module provides access functions to the FusionAuth JWT API.
Most functions require a Tesla Client struct created with FusionAuth.client(base_url, api_key, tenant_id)
.
Those that use JWT Authentication may require a different api_key
structure.
See JWT Authentication for examples of how you can send the JWT to FusionAuth.
Link to this section Summary
Functions
Retrieve a single Public Key for a specific Application by Application Id
Retrieve a single Public Key by Key Identifier
Retrieve all Public Keys
Retrieve Refresh Tokens issued to a User
Retrieve Refresh Tokens issued to a User by User ID
Issue an Access Token by Application ID
Request a new Access Token by presenting a valid Refresh Token
Revoke a single Refresh Token
Revoke all Refresh Tokens for an entire Application
Revoke all Refresh Tokens issued to a User
Validate Access Token
Link to this section Types
Specs
client() :: FusionAuth.client()
Specs
result() :: FusionAuth.result()
Link to this section Functions
Specs
Retrieve a single Public Key for a specific Application by Application Id
For more information, visit the FusionAuth API Documentation for Retrieve Public Keys.
Specs
Retrieve a single Public Key by Key Identifier
For more information, visit the FusionAuth API Documentation for Retrieve Public Keys.
Specs
Retrieve all Public Keys
This API is used to retrieve Public Keys generated by FusionAuth, used used to cryptographically verify JWT signatures signed using the corresponding RSA or ECDSA private key.
For more information, visit the FusionAuth API Documentation for Retrieve Public Keys.
Specs
Retrieve Refresh Tokens issued to a User
This API will use a JWT as authentication. See JWT Authentication for examples of how you can send the JWT to FusionAuth.
Examples
iex> FusionAuth.JWT.get_user_refresh_tokens(client, token)
{
:ok,
%{
"refreshTokens" => [...]
},
%Tesla.Env{...}
}
For more information, visit the FusionAuth API Documentation for Retrieve Refresh Tokens.
Specs
Retrieve Refresh Tokens issued to a User by User ID
Examples
iex> FusionAuth.JWT.get_user_refresh_tokens_by_user_id(client, user_id)
{
:ok,
%{
"refreshTokens" => [...]
},
%Tesla.Env{...}
}
For more information, visit the FusionAuth API Documentation for Retrieve Refresh Tokens.
issue_jwt_by_application_id(client, token, application_id, refresh_token)
View SourceSpecs
Issue an Access Token by Application ID
This API is used to issue a new access token (JWT) using an existing access token (JWT).
This API provides the single signon mechanism for access tokens. For example you have an access token for application A and you need an access token for application B. You may use this API to request an access token to application B with the authorized token to application A. The returned access token will have the same expiration of the one provided.
This API will use a JWT as authentication. See JWT Authentication for examples of how you can send the JWT to FusionAuth.
Examples
iex> FusionAuth.JWT.issue_jwt_by_application_id(client, token, application_id, refresh_token)
{
:ok,
%{
"token" => "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjY1NTYzYjY5OSJ9.eyJhdWQiOiIzYzIxOWU1OC1lZDBlLTRiMTgtYWQ0OC1mNGY5Mjc5M2FlMzIiLCJleHAiOjE1OTE4MTk2ODksImlhdCI6MTU5MTgxNjcxMSwiaXNzIjoiYWNtZS5jb20iLCJzdWIiOiJmZmZjODY0OC1iYWIyLTRiZGQtYjJlYi1hNDhlODUzZDkyMTciLCJhdXRoZW50aWNhdGlvblR5cGUiOiJKV1RfU1NPIiwiZW1haWwiOiJhZGVsYWNydXpAY29naWxpdHkuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImFwcGxpY2F0aW9uSWQiOiIzYzIxOWU1OC1lZDBlLTRiMTgtYWQ0OC1mNGY5Mjc5M2FlMzIiLCJyb2xlcyI6WyJhZG1pbiJdfQ.c9Nyx9UucmALsIueJPWlOOXAC_FkcHeMCInrgdv3zQU"
},
%Tesla.Env{...}
}
iex>
For more information, visit the FusionAuth API Documentation for Issue a JWT.
Specs
Reconcile a JWT
The Reconcile API is used to take a JWT issued by a third party identity provider as described by an Identity Provider configuration and reconcile the User represented by the JWT to FusionAuth.
For more information, visit the FusionAuth API Documentation for Reconcile a JWT.
Specs
Request a new Access Token by presenting a valid Refresh Token
The refresh token may be provided either in the HTTP request body or as a cookie. If both are provided, the cookie will take precedence.
Examples
iex> FusionAuth.JWT.refresh_jwt(client, refresh_token, token)
{
:ok,
%{
"token" => "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IjY1NTYzYjY5OSJ9.eyJhdWQiOiJmN2E3MmFkMS1kZTZhLTQxMmYtYTM3Mi1lNjg5YTNiN2FkY2IiLCJleHAiOjE1OTE4MTk2ODksImlhdCI6MTU5MTgxNjA4OSwiaXNzIjoiYWNtZS5jb20iLCJzdWIiOiJmZmZjODY0OC1iYWIyLTRiZGQtYjJlYi1hNDhlODUzZDkyMTciLCJhdXRoZW50aWNhdGlvblR5cGUiOiJSRUZSRVNIX1RPS0VOIiwiZW1haWwiOiJhZGVsYWNydXpAY29naWxpdHkuY29tIiwiZW1haWxfdmVyaWZpZWQiOnRydWUsImFwcGxpY2F0aW9uSWQiOiJmN2E3MmFkMS1kZTZhLTQxMmYtYTM3Mi1lNjg5YTNiN2FkY2IiLCJyb2xlcyI6W119.5orARQLfaMYmoOLfxrcWMqRW9_eog5g5l4OivPovGEE"
},
%Tesla.Env{...}
}
For more information, visit the FusionAuth API Documentation for Refresh a JWT.
Specs
Revoke a single Refresh Token
This API may be authenticated using an Access Token. See Authentication for examples of authenticating using an Access Token. The token owner must match the identity in the access token if provided to be successful.
Examples
iex> FusionAuth.JWT.revoke_refresh_token(client, token)
{
:ok,
"",
%Tesla.Env{...}
}
For more information, visit the FusionAuth API Documentation for Revoke Refresh Tokens.
Specs
Revoke all Refresh Tokens for an entire Application
Examples
iex> JWT.revoke_refresh_tokens_by_application_id(client, application_id)
{
:ok,
"",
%Tesla.Env{...}
}
For more information, visit the FusionAuth API Documentation for Revoke Refresh Tokens.
Specs
Revoke all Refresh Tokens issued to a User
Examples
iex> FusionAuth.JWT.revoke_refresh_token(client, user_id)
{
:ok,
"",
%Tesla.Env{...}
}
For more information, visit the FusionAuth API Documentation for Revoke Refresh Tokens.
Specs
Validate Access Token
The access token can be provided to the API using an HTTP request header, or a cookie. The response body will contain the decoded JWT payload.
Examples
iex> FusionAuth.JWT.validate_jwt(client, token)
{
:ok,
%{
"jwt" => %{
"authenticationType" => "PASSWORD",
"email" => "email@address.com",
"email_verified" => true,
"exp" => 1591815558,
"iat" => 1591811958,
"iss" => "acme.com",
"sub" => "fffc8648-bab2-4bdd-b2eb-a48e853d9217"
}
},
%Tesla.Env{...}
}
For more information, visit the FusionAuth API Documentation for Validate a JWT.