Skip to content

Commit f45173b

Browse files
authored
Chore/readme refactor (#255)
* Move config examples to a separate folder * Remove contributors from the readme, because it does not scale * Fix url link to config example
1 parent 26e56fb commit f45173b

File tree

11 files changed

+353
-378
lines changed

11 files changed

+353
-378
lines changed

README.md

Lines changed: 12 additions & 378 deletions
Large diffs are not rendered by default.

docs/config-examples/aws-cognito.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# AWS Cognito
2+
3+
First, set up a your user pool in [the AWS console](https://eu-west-1.console.aws.amazon.com/cognito). In the details of your new user pool, go down to `App clients` to create a new client. Make sure you create a client **without** a client secret (it's redundant on mobile). You should get an alphanumeric string which is your `<CLIENT_ID>`.
4+
5+
Now you need to set up your domain name. This will be on the left menu in your pool details page, under App Integration -> Domain Name. What this is depends on your preference. E.g. for AppAuth demo, mine is `https://app-auth-test.auth.eu-west-1.amazoncognito.com` as I chose `app-auth-test` as the domain and `eu-west-1` as the region.
6+
7+
Finally, you need to configure your app client. Go to App Integration -> App Client Settings.
8+
9+
1. Enable your newly created user pool under Enabled Identity Providers.
10+
2. Add the callback url (must be same as in your config, e.g. `com.myclientapp://myclient/redirect`)
11+
3. Enable the Authorization code grant
12+
4. Enable openid scope
13+
14+
```js
15+
const config = {
16+
clientId: '<YOUR_CLIENT_ID>',
17+
redirectUrl: 'com.myclientapp://myclient/redirect',
18+
serviceConfiguration: {
19+
authorizationEndpoint: '<YOUR_DOMAIN_NAME>/oauth2/authorize',
20+
tokenEndpoint: '<YOUR_DOMAIN_NAME>/oauth2/token',
21+
revocationEndpoint: '<YOUR_DOMAIN_NAME>/oauth2/revoke'
22+
}
23+
};
24+
25+
// Log in to get an authentication token
26+
const authState = await authorize(config);
27+
28+
// Refresh token
29+
const refreshedState = await refresh(config, {
30+
refreshToken: authState.refreshToken,
31+
});
32+
33+
// Revoke token
34+
await revoke(config, {
35+
tokenToRevoke: refreshedState.refreshToken
36+
});
37+
```
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Azure Active Directory
2+
3+
Azure Active Directory [does not specify a revocation endpoint](https://docs.microsoft.com/en-us/azure/active-directory/active-directory-configurable-token-lifetimes#access-tokens) because the access token are not revokable. Therefore `revoke` functionality doesn't work.
4+
5+
See the [Azure docs on requesting an access token](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-code#request-an-authorization-code) for more info on additional parameters.
6+
7+
Please Note:
8+
9+
* The [Azure docs](https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-protocols-oauth-code#request-an-authorization-code) recommend `'urn:ietf:wg:oauth:2.0:oob'` as the `redirectUrl`.
10+
* `Scopes` is ignored.
11+
* `additionalParameters.resource` may be required based on the tenant settings.
12+
13+
```js
14+
const config = {
15+
issuer: 'https://login.microsoftonline.com/your-tenant-id',
16+
clientId: 'your-client-id',
17+
redirectUrl: 'urn:ietf:wg:oauth:2.0:oob',
18+
scopes: [], // ignored by Azure AD
19+
additionalParameters: {
20+
resource: 'your-resource'
21+
}
22+
};
23+
24+
// Log in to get an authentication token
25+
const authState = await authorize(config);
26+
27+
// Refresh token
28+
const refreshedState = await refresh(config, {
29+
refreshToken: authState.refreshToken,
30+
});
31+
```

docs/config-examples/dropbox.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Dropbox
2+
3+
Dropbox provides an OAuth 2.0 endpoint for logging in with a Dropbox user's credentials. You'll need to first [register your Dropbox application here](https://www.dropbox.com/developers/apps/create).
4+
5+
Please note:
6+
7+
* Dropbox does not provide a OIDC discovery endpoint, so `serviceConfiguration` is used instead.
8+
* Dropbox OAuth requires a [client secret](#note-about-client-secrets).
9+
* Dropbox OAuth does not allow non-https redirect URLs, so you'll need to use a [Universal Link on iOS](https://developer.apple.com/library/archive/documentation/General/Conceptual/AppSearch/UniversalLinks.html) or write a HTTPS endpoint.
10+
* Dropbox OAuth does not provide refresh tokens or a revoke endpoint.
11+
12+
```js
13+
const config = {
14+
clientId: 'your-client-id-generated-by-dropbox',
15+
clientSecret: 'your-client-secret-generated-by-dropbox',
16+
redirectUrl: 'https://native-redirect-endpoint/oauth/dropbox',
17+
scopes: [],
18+
serviceConfiguration: {
19+
authorizationEndpoint: 'https://www.dropbox.com/oauth2/authorize',
20+
tokenEndpoint: `https://www.dropbox.com/oauth2/token`,
21+
},
22+
useNonce: false,
23+
usePKCE: false,
24+
};
25+
26+
// Log in to get an authentication token
27+
const authState = await authorize(config);
28+
const dropboxUID = authState.tokenAdditionalParameters.account_id;
29+
```

docs/config-examples/fitbit.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Fitbit
2+
3+
Fitbit provides an OAuth 2.0 endpoint for logging in with a Fitbit user's credentials. You'll need to first [register your Fitbit application here](https://dev.fitbit.com/apps/new).
4+
5+
Please note:
6+
7+
* Fitbit does not provide a OIDC discovery endpoint, so `serviceConfiguration` is used instead.
8+
* Fitbit OAuth requires a [client secret](#note-about-client-secrets).
9+
10+
```js
11+
const config = {
12+
clientId: 'your-client-id-generated-by-fitbit',
13+
clientSecret: 'your-client-secret-generated-by-fitbit',
14+
redirectUrl: 'com.whatever.url.you.configured.in.fitbit.oauth://redirect', //note: path is required
15+
scopes: ['activity', 'sleep'],
16+
serviceConfiguration: {
17+
authorizationEndpoint: 'https://www.fitbit.com/oauth2/authorize',
18+
tokenEndpoint: 'https://api.fitbit.com/oauth2/token',
19+
revocationEndpoint: 'https://api.fitbit.com/oauth2/revoke'
20+
}
21+
};
22+
23+
// Log in to get an authentication token
24+
const authState = await authorize(config);
25+
26+
// Refresh token
27+
const refreshedState = await refresh(config, {
28+
refreshToken: authState.refreshToken,
29+
});
30+
31+
// Revoke token
32+
await revoke(config, {
33+
tokenToRevoke: refreshedState.refreshToken
34+
});
35+
```

docs/config-examples/google.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Google
2+
3+
Full support out of the box.
4+
5+
```js
6+
const config = {
7+
issuer: 'https://accounts.google.com',
8+
clientId: 'GOOGLE_OAUTH_APP_GUID.apps.googleusercontent.com',
9+
redirectUrl: 'com.googleusercontent.apps.GOOGLE_OAUTH_APP_GUID:/oauth2redirect/google',
10+
scopes: ['openid', 'profile', 'offline_access']
11+
};
12+
13+
// Log in to get an authentication token
14+
const authState = await authorize(config);
15+
16+
// Refresh token
17+
const refreshedState = await refresh(config, {
18+
refreshToken: authState.refreshToken
19+
});
20+
21+
// Revoke token
22+
await revoke(config, {
23+
tokenToRevoke: refreshedState.refreshToken
24+
});
25+
```
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Identity Server 3
2+
3+
This library supports authenticating with Identity Server 3. The only difference from
4+
Identity Server 4 is that it requires a `clientSecret` and there is no way to opt out of it.
5+
6+
```js
7+
// You must include a clientSecret
8+
const config = {
9+
issuer: 'your-identityserver-url',
10+
clientId: 'your-client-id',
11+
clientSecret: 'your-client-secret',
12+
redirectUrl: 'com.your.app.name:/oauthredirect',
13+
scopes: ['openid', 'profile', 'offline_access']
14+
};
15+
16+
// Log in to get an authentication token
17+
const authState = await authorize(config);
18+
19+
// Refresh token
20+
const refreshedState = await refresh(config, {
21+
refreshToken: authState.refreshToken,
22+
});
23+
24+
// Revoke token, note that Identity Server expects a client id on revoke
25+
await revoke(config, {
26+
tokenToRevoke: refreshedState.refreshToken,
27+
sendClientId: true
28+
});
29+
```
30+
31+
<details>
32+
<summary>Example server configuration</summary>
33+
34+
```
35+
var client = new Client
36+
{
37+
ClientId = "native.code",
38+
ClientName = "Native Client (Code with PKCE)",
39+
Flow = Flows.AuthorizationCodeWithProofKey,
40+
RedirectUris = { "com.your.app.name:/oauthredirect" },
41+
ClientSecrets = new List<Secret> { new Secret("your-client-secret".Sha256()) },
42+
AllowAccessToAllScopes = true
43+
};
44+
```
45+
46+
</details>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Identity Server 4
2+
3+
This library supports authenticating for Identity Server 4 out of the box. Some quirks:
4+
5+
1. In order to enable refresh tokens, `offline_access` must be passed in as a scope variable
6+
2. In order to revoke the access token, we must sent client id in the method body of the request.
7+
This is not part of the OAuth spec.
8+
9+
```js
10+
// Note "offline_access" scope is required to get a refresh token
11+
const config = {
12+
issuer: 'https://demo.identityserver.io',
13+
clientId: 'native.code',
14+
redirectUrl: 'io.identityserver.demo:/oauthredirect',
15+
scopes: ['openid', 'profile', 'offline_access']
16+
};
17+
18+
// Log in to get an authentication token
19+
const authState = await authorize(config);
20+
21+
// Refresh token
22+
const refreshedState = await refresh(config, {
23+
refreshToken: authState.refreshToken,
24+
});
25+
26+
// Revoke token, note that Identity Server expects a client id on revoke
27+
await revoke(config, {
28+
tokenToRevoke: refreshedState.refreshToken,
29+
sendClientId: true
30+
});
31+
```
32+
33+
<details>
34+
<summary>Example server configuration</summary>
35+
36+
```
37+
var client = new Client
38+
{
39+
ClientId = "native.code",
40+
ClientName = "Native Client (Code with PKCE)",
41+
RequireClientSecret = false,
42+
RedirectUris = { "io.identityserver.demo:/oauthredirect" },
43+
AllowedGrantTypes = GrantTypes.Code,
44+
RequirePkce = true,
45+
AllowedScopes = { "openid", "profile" },
46+
AllowOfflineAccess = true
47+
};
48+
```
49+
50+
</details>

docs/config-examples/keycloak.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Keycloak
2+
3+
Keycloak [does not specify a revocation endpoint](http://keycloak-user.88327.x6.nabble.com/keycloak-user-Revoking-an-OAuth-Token-td3041.html) so revoke functionality doesn't work.
4+
5+
If you use [JHipster](http://www.jhipster.tech/)'s default Keycloak Docker image, everything will work with the following settings, except for revoke.
6+
7+
```js
8+
const config = {
9+
issuer: 'http://localhost:9080/auth/realms/jhipster',
10+
clientId: 'web_app',
11+
redirectUrl: '<YOUR_REDIRECT_SCHEME>:/callback'
12+
scopes: ['openid', 'profile']
13+
};
14+
15+
// Log in to get an authentication token
16+
const authState = await authorize(config);
17+
18+
// Refresh token
19+
const refreshedState = await refresh(config, {
20+
refreshToken: authState.refreshToken,
21+
});
22+
```

docs/config-examples/okta.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Okta
2+
3+
Full support out of the box.
4+
5+
> If you're using Okta and want to add App Auth to your React Native application, you'll need an application to authorize against. If you don't have an Okta Developer account, [you can signup for free](https://developer.okta.com/signup/).
6+
>
7+
> Log in to your Okta Developer account and navigate to **Applications** > **Add Application**. Click **Native** and click the **Next** button. Give the app a name you’ll remember (e.g., `React Native`), select `Refresh Token` as a grant type, in addition to the default `Authorization Code`. Copy the **Login redirect URI** (e.g., `com.oktapreview.dev-158606:/callback`) and save it somewhere. You'll need this value when configuring your app.
8+
>
9+
> Click **Done** and you'll see a client ID on the next screen. Copy the redirect URI and clientId values into your App Auth config.
10+
11+
```js
12+
const config = {
13+
issuer: 'https://{yourOktaDomain}.com/oauth2/default',
14+
clientId: '{clientId}',
15+
redirectUrl: 'com.{yourReversedOktaDomain}:/callback',
16+
scopes: ['openid', 'profile']
17+
};
18+
19+
// Log in to get an authentication token
20+
const authState = await authorize(config);
21+
22+
// Refresh token
23+
const refreshedState = await refresh(config, {
24+
refreshToken: authState.refreshToken,
25+
});
26+
27+
// Revoke token
28+
await revoke(config, {
29+
tokenToRevoke: refreshedState.refreshToken
30+
});
31+
```

0 commit comments

Comments
 (0)