- Notifications
You must be signed in to change notification settings - Fork0
Redirection of OAuth2 response to any URL.
License
czetech/oauthuri
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
OAuthURI solves the problem if the OAuth2 authorization provider does not allowto 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 OAuth2provider. The JSON string must be used as thestate
parameter, where inaddition to the originalstate
data, there are the keysredirect_uri
withthe final URL andresponse_mode
with the final mode (query
,fragment
orform_post
). OAuthURI simply redirects the request further to the URL from theparameters.
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 aquery
,fragment
, orform_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 instate JSON | "redirect_uri" |
keyResponseMode | Key to response mode instate JSON | "response_mode" |
SeeUsage options on how to use them.
The application is a static web page where the response from OAuth2 providermust point toredirect.html and the configuration is in theconfig.jsonfile.
OAuthURI can also be used as a JavaScript library.
Application is deployed athttps://oauthuri.cze.tech. The URL for responsefrom 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 redirectPOST requests to the GET and send the data as a query string (see the Nginxconfiguration example indocker-nginx.conf).
The Dockerfile and Helm chart are also part of this repository so it can beeasily 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 beconfigured usingconfig.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 thechart 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 packageoauthuri.
It is installed with:
npm install oauthuri
Or it is possible to use UMD module from the CDN:
<scriptsrc="https://unpkg.com/oauthuri"></script>
Usage:
constoAuthURI=newOAuthURI(redirectUri,responseMode,keyRedirectUri,keyResponseMode);oAuthURI.redirect();
The source code is available athttps://github.com/czetech/oauthuri.
About
Redirection of OAuth2 response to any URL.