- Run
npm install
- Rename
.env.sample
to.env
and populate the variables accordingly. - Run
npm run start
Assuming the Broker is running for the first time on your machine, you would need to manually add a new Client and Provider. For the Client, you could use the existing test client that is bootstrapped with the Broker, or create your own with Admin client credentials. The easiest way is to use the test Client bootstrapped with the provider and the following steps assume we are using this bootstrapped test client.
Before making any request to the Broker, to get an auth token, make a POST
request to the following Broker endpoint: http://{{host}}:{{port}}/auth/service
with the following header:
Basic: <base64encoded(ffffffff-ffff-ffff-ffff-ffffffffffff:TEST)>
With the token returned above as an Authorization: Bearer <token>
header, make a PUT
request to the following Broker endpoint: http://{{host}}:{{port}}/providers
with the following body
{
"name": "provider-name",
"authUri": "https://example.com/o/oauth2/v2/auth",
"tokenUri": "https://example.com/token",
"redirectUri": "http://localhost:3000/oauth/callback",
"clientId": "abc",
"clientSecret": "123",
"config": {
"moreCustomQueryParams": "ok"
}
}
The config object is a single-level string-only JSON object that will be appended to the authorization URL as query params. In the example above, &moreCustomQueryParams=ok
will be appended. It can be left blank in the payload if not needed.
- Enter the Broker client ID and client secret. Clicking Authorize with broker will load the auth token.
- Once loaded, and assuming Providers are available, select the appropriate Provider.
- If a config is available, it will show here. Otherwise, enter it in JSON format. E.g.
{
"moreCustomQueryParams": "ok"
}
- Click Update config to store the updated config with the Provider.
- Enter a token key. If not, the default token key will be used. A token key the key with which your OAuth token is stored with the Broker. It is unique to the Client ID and Provider name.
- Enter any additional query params needed for the authorization part of the OAuth transaction in the form
abc=123&xyz=420
. This is typically documented for you on the Provider's documentation. For example, this is Google's. - Click Get OAuth URL from broker and a redirectable auth URL will be returned from the Broker.
- Click Redirect to provider will redirect to the provider to ask for user authorization and consent.
- Assuming the Provider authenticated and authorized the user successfully, a new tab will be opened with a success page. On clicking Reload, you will see the latest token associated with the user and token key.
- Clicking Reset has the same effect as reloading the page and will clear all values, including the auth token.