OAuthURI solves the problem if the OAuth2 authorization provider does not allow to use the redirect URI that is needed, e.g. localhost, mobile app deep linking, or an HTTP scheme for testing purposes.
URL of the OAuthURI instance is set to the allowed redirect URIs of the OAuth2
provider. The JSON string must be used as the state
parameter, where in
addition to the original state
data, there are the keys redirect_uri
with
the final URL and response_mode
with the final mode (query
, fragment
or
form_post
). OAuthURI simply redirects the request further to the URL from the
parameters.
Example of OAuth2 request:
{
"scope": "<scope>",
"client_id": "<client ID>",
"redirect_uri": "https://<OAuthURI host>/redirect",
"state": "{\"redirect_uri\":\"myapp://deeplink\",\"state\":\"<state data>\"}"
}
The response from OAuth2 provider to OAuthURI can be a query
, fragment
, or
form_post
.
There are several configuration variables:
Name | Description | Default value |
---|---|---|
redirectUri |
Default redirect URI value | null |
responseMode |
Default response mode value | "query" |
keyRedirectUri |
Key to redirect URI in state JSON |
"redirect_uri" |
keyResponseMode |
Key to response mode in state JSON |
"response_mode" |
See Usage options on how to use them.
The application is a static web page where the response from OAuth2 provider must point to redirect.html and the configuration is in the config.json file.
OAuthURI can also be used as a JavaScript library.
Application is deployed at https://oauthuri.cze.tech. The URL for response from OAuth2 provider is:
https://oauthuri.cze.tech/redirect
Feel free to use the service for testing or simple production purposes.
Requirements:
Build is done with:
make
then the output is in the ./build/web directory. The web server must redirect POST requests to the GET and send the data as a query string (see the Nginx configuration example in docker-nginx.conf).
The Dockerfile and Helm chart are also part of this repository so it can be easily build and deployed to Kubernetes.
Run the image from Docker Hub:
docker run -p 80:80 czetech/oauthuri
The endpoint for a response from OAuth2 provider is /redirect. The image can be configured using config.json file mounted to /app/config.json.
Setup Helm repository:
helm repo add czetech https://charts.cze.tech/
Install Helm chart:
helm install oauthuri czetech/oauthuri \
--set ingress.enabled=true \
--set ingress.hosts[0]=<ingress-host>
see the chart for more options.
As in the Docker image, the endpoint for a response from OAuth2 provider is /redirect. Configuration variables can be passed to the Helm chart.
OAuthURI as a JavaScript front-end library is available as npm package oauthuri.
It is installed with:
npm install oauthuri
Or it is possible to use UMD module from the CDN:
<script src="https://unpkg.com/oauthuri"></script>
Usage:
const oAuthURI = new OAuthURI(
redirectUri,
responseMode,
keyRedirectUri,
keyResponseMode
);
oAuthURI.redirect();
The source code is available at https://github.com/czetech/oauthuri.