This is a quick project that shows the Tyk OAuth request cycle from start to finish.
To try this project out:
- In your Tyk Gateway, create an API and call it
oauth2
- Set the Access Method to "Oauth 2.0"
- Select "Allowed Access Types: Authorization codes"
- Select "Allowed Authorize Types: Token"
- Set the login redirect for this API to be:
http://localhost:8000/login
- Take note of the API ID
- Add an oauth client to it and set the redirect to be
http://localhost:8000/final
- Take note of the client ID
- Create a policy that has access to this API, take not of the Policy ID
Now edit the tmpl/index.html
file:
- In the form elements, set the
redirect_uri
value to the one of your client - Set the
client_id
element to the value of your client ID
Now edit config.go
:
- Set the
APIlistenPath
tooauth2
(or whatever the listen path is for your OAuth API) - Set
orgID
to be your Org ID (Go to users -> select your user, it is under RPC credentials) - Set
policyID
to be your policy ID - Set
GatewayHost
to be the host path to your gateway e.g. http://domain.com:port (note no trailing slash) - Set
AdminSecret
to your the secret in yourtyk.conf
Now run the app:
go run *.go
Then visit:
If you've set everything up correctly, you should be taken throguh a full OAuth flow.
This app emulates two parties:
- The requester (client)
- The identity provider portal (your login page)
We make use of the Tyk REST API Authorization endpoint to complete the request cycle, you can see an API client in the util.go
file.