Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support manual service configuration #52

Merged
merged 22 commits into from
Feb 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
8972232
First naive stab at passing serviceConfiguration manually
jevakallio Feb 21, 2018
927c92c
Naive implementation of manually configured refreshing + client secre…
jevakallio Feb 21, 2018
4f965f6
Add support for revocation with manual service configuration
jevakallio Feb 21, 2018
a5e0bce
Make clientSecret a native method parameter instead of bundling in ad…
jevakallio Feb 21, 2018
851311d
Initial implementation of manual configuration for ios
jevakallio Feb 21, 2018
23cd1bc
Accept clientSecret as a parameter to authorize/refresh
jevakallio Feb 21, 2018
feb40c6
Update tests
jevakallio Feb 21, 2018
b60855b
Add typescript definitions
jevakallio Feb 21, 2018
547b0de
Update readme
jevakallio Feb 21, 2018
4003e4f
Add support for registrationEndpoint, refactor
jevakallio Feb 21, 2018
d4d205a
Refactor and clean up
jevakallio Feb 21, 2018
80f55a6
Fix discovered revocation endpoint url
jevakallio Feb 21, 2018
6bfa668
Fix revocation endpoint validation
jevakallio Feb 21, 2018
24f36f8
Example of using serviceConfiguration + clientSecret with Uber
jevakallio Feb 21, 2018
b2abfbd
Update tests for error messages
jevakallio Feb 21, 2018
04c58f0
Comment out (but intentionally leave in) manual serviceConfiguration …
jevakallio Feb 21, 2018
8587380
Fix typo in readme
jevakallio Feb 22, 2018
bd7dfbb
Better error messages
jevakallio Feb 22, 2018
e49bd87
Remove autogenerated comments
jevakallio Feb 22, 2018
5239f90
Fix typo in error message
jevakallio Feb 22, 2018
a3775c5
Fix typos in README
jevakallio Feb 22, 2018
08abd47
Fix typos in error messages
jevakallio Feb 22, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ const config = {
redirectUrl: 'io.identityserver.demo:/oauthredirect',
additionalParameters: {},
scopes: ['openid', 'profile', 'email', 'offline_access']

// serviceConfiguration: {
// authorizationEndpoint: 'https://demo.identityserver.io/connect/authorize',
// tokenEndpoint: 'https://demo.identityserver.io/connect/token',
// revocationEndpoint: 'https://demo.identityserver.io/connect/revoke'
// }
};

export default class App extends Component<{}, State> {
Expand All @@ -41,7 +47,7 @@ export default class App extends Component<{}, State> {
authorize = async () => {
try {
const authState = await authorize(config);

this.animateState(
{
hasLoggedInOnce: true,
Expand Down
54 changes: 52 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,14 +72,20 @@ const result = await authorize(config);
This is your configuration object for the client. The config is passed into each of the methods
with optional overrides.

* **issuer** - (`string`) _REQUIRED_ the url of the auth server
* **issuer** - (`string`) base URI of the authentication server. If no `serviceConfiguration` (below) is provided, issuer is a mandatory field, so that the configuration can be fetched from the issuer's [OIDC discovery endpoint](https://openid.net/specs/openid-connect-discovery-1_0.html).
* **serviceConfiguration** - (`object`) you may manually configure token exchange endpoints in cases where the issuer does not support the OIDC discovery protocol, or simply to avoid an additional round trip to fetch the configuration. If no `issuer` (above) is provided, the service configuration is mandatory.
* **authorizationEndpoint** - (`string`) _REQUIRED_ fully formed url to the OAuth authorization endpoint
* **tokenEndpoint** - (`string`) _REQUIRED_ fully formed url to the OAuth token exchange endpoint
* **revocationEndpoint** - (`string`) fully formed url to the OAuth token revocation endpoint. If you want to be able to revoke a token and no `issuer` is specified, this field is mandatory.
* **registrationEndpoint** - (`string`) fully formed url to your OAuth/OpenID Connect registration endpoint. Only necessary for servers that require client registration.
* **clientId** - (`string`) _REQUIRED_ your client id on the auth server
* **clientSecret** - (`string`) client secret to pass to token exchange requests. :warning: Read more about [client secrets](#note-about-client-secrets)
* **redirectUrl** - (`string`) _REQUIRED_ the url that links back to your app with the auth code
* **scopes** - (`array<string>`) _REQUIRED_ the scopes for your token, e.g. `['email', 'offline_access']`
* **additionalParameters** - (`object`) additional parameters that will be passed in the authorization request.
Must be string values! E.g. setting `additionalParameters: { hello: 'world', foo: 'bar' }` would add
`hello=world&foo=bar` to the authorization request.
* :warning: **dangerouslyAllowInsecureHttpRequests** - (`boolean`) _ANDROID_ whether to allow requests over plain HTTP or with self-signed SSL certificates. Can be useful for testing against local server, _should not be used in production._ This setting has no effect on iOS; to enable insecure HTTP requests, add a [NSExceptionAllowsInsecureHTTPLoads exception](https://cocoacasts.com/how-to-add-app-transport-security-exception-domains) to your App Transport Security settings.
* **dangerouslyAllowInsecureHttpRequests** - (`boolean`) _ANDROID_ whether to allow requests over plain HTTP or with self-signed SSL certificates. :warning: Can be useful for testing against local server, _should not be used in production._ This setting has no effect on iOS; to enable insecure HTTP requests, add a [NSExceptionAllowsInsecureHTTPLoads exception](https://cocoacasts.com/how-to-add-app-transport-security-exception-domains) to your App Transport Security settings.

#### result

Expand Down Expand Up @@ -353,6 +359,14 @@ try {

See example configurations for different providers below.

### Note about client secrets

Some authentication providers, including examples cited below, require you to provide a client secret. The authors of the AppAuth library

> [strongly recommend](https://github.com/openid/AppAuth-Android#utilizing-client-secrets-dangerous) you avoid using static client secrets in your native applications whenever possible. Client secrets derived via a dynamic client registration are safe to use, but static client secrets can be easily extracted from your apps and allow others to impersonate your app and steal user data. If client secrets must be used by the OAuth2 provider you are integrating with, we strongly recommend performing the code exchange step on your backend, where the client secret can be kept hidden.

Having said this, in some cases using client secrets is unavoidable. In these cases, a `clientSecret` parameter can be provided to `authorize`/`refresh` calls when performing a token request.

### Identity Server 4

This library supports authenticating for Identity Server 4 out of the box. Some quirks:
Expand Down Expand Up @@ -467,6 +481,42 @@ const refreshedState = await refresh(config, {
});
```

### Uber

Uber provides an OAuth 2.0 endpoint for logging in with a Uber user's credentials. You'll need to first [create an Uber OAuth application here](https://developer.uber.com/docs/riders/guides/authentication/introduction).

Please note:

* Uber does not provide a OIDC discovery endpoint, so `serviceConfiguration` is used instead.
* Uber OAuth requires a [client secret](#note-about-client-secrets).

```js
const config = {
clientId: 'your-client-id-generated-by-uber',
clientSecret: 'your-client-secret-generated-by-uber',
redirectUrl: 'com.whatever.url.you.configured.in.uber.oauth://redirect', //note: path is required
scopes: ['profile', 'delivery'], // whatever scopes you configured in Uber OAuth portal
serviceConfiguration: {
authorizationEndpoint: 'https://login.uber.com/oauth/v2/authorize',
tokenEndpoint: 'https://login.uber.com/oauth/v2/token',
revocationEndpoint: 'https://login.uber.com/oauth/v2/revoke'
}
};

// Log in to get an authentication token
const authState = await authorize(config);

// Refresh token
const refreshedState = await refresh(config, {
refreshToken: authState.refreshToken,
});

// Revoke token
await revoke(config, {
tokenToRevoke: refreshedState.refreshToken
});
```

## Contributors

Thanks goes to these wonderful people
Expand Down
Loading