Skip to content

Commit 2b9fcf9

Browse files
author
Kadi Kraman
committed
Update documentation & address code review comments
1 parent af871e8 commit 2b9fcf9

File tree

6 files changed

+136
-74
lines changed

6 files changed

+136
-74
lines changed

.babelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
{
2-
"presets": ["es2015"]
2+
"presets": ["babel-preset-react-native"]
33
}

LICENSE

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2013
3+
Copyright (c) 2017 Formidable Labs
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in

README.md

+21-15
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,41 @@
1-
# react-native-app-auth
1+
# React Native App Auth
22

33
React Native bridge for ![AppAuth-iOS](https://github.com/openid/AppAuth-iOS) and ![AppAuth-Android](https://github.com/openid/AppAuth-Android) - an SDK for communicating with OAuth2 providers. It also supports the PKCE extension to OAuth.
44

5-
In theory, the library should support any OAuth provider that implements the ![OAuth2 spec](https://tools.ietf.org/html/rfc6749#section-2.2) and it has been tested with:
5+
This library *should* support any OAuth provider that implements the ![OAuth2 spec](https://tools.ietf.org/html/rfc6749#section-2.2) but it has only been tested with:
66

77
- ![Identity Server4](https://demo.identityserver.io/)
88
- ![Google](https://developers.google.com/identity/protocols/OAuth2)
99

10-
Supported methods:
10+
The library uses auto-discovery which mean it relies on the the ![.well-known/openid-configuration](https://openid.net/specs/openid-connect-discovery-1_0.html) endpoint to discover all auth endpoints automatically. It will be possible to extend the library later to add custom configuration.
1111

12-
### authorize()
12+
# Supported methods:
13+
14+
### authorize
15+
This is the main function to use for authentication. Evoking this function will do the whole login flow and returns the access token, refresh token and access token expiry date when successful, or it throws an error when not successful.
1316
```
14-
await AppAuth.authorize(scopes);
17+
import AppAuth from 'react-native-app-auth';
18+
19+
const appAuth = new AppAuth(config);
20+
const result = await AppAuth.authorize(scopes);
1521
// returns accessToken, accessTokenExpirationDate and refreshToken
1622
```
1723

18-
### refresh()
24+
### refresh
25+
This method will refresh the accessToken using the refreshToken. Some auth providers will also give you a new refreshToken
1926
```
2027
await AppAuth.refresh(refreshToken, scopes);
21-
// returns accessTokenExpirationDate
28+
// returns accessToken, accessTokenExpirationDate and (maybe) refreshToken
2229
```
2330

24-
### revokeToken()
31+
### revokeToken
32+
This method will revoke a token. The tokenToRevoke can be either an accessToken or a refreshToken
2533
```
2634
// note, sendClientId=true will only be required when using IdentityServer
2735
await AppAuth.revokeToken(tokenToRevoke, sendClientId);
2836
```
2937

30-
## Getting started
38+
# Getting started
3139

3240
`$ npm install react-native-app-auth --save`
3341

@@ -123,7 +131,7 @@ manifestPlaceholders = [
123131

124132

125133

126-
## Usage
134+
# Usage
127135
```javascript
128136
import AppAuth from 'react-native-app-auth';
129137

@@ -132,8 +140,6 @@ const appAuth = new AppAuth({
132140
issuer: '<YOUR_ISSUER_URL>',
133141
clientId: '<YOUR_CLIENT_ID',
134142
redirectUrl: '<YOUR_REDIRECT_URL>',
135-
revokeTokenUrl: '<YOUR_REVOKE_TOKEN_URL>',
136-
allowOfflineAccess: true,
137143
});
138144

139145
// use the client to make the auth request and receive the authState
@@ -146,12 +152,12 @@ try {
146152
}
147153
```
148154

149-
## Support
155+
# Support
150156

151-
### Identity Server 4
157+
## Identity Server 4
152158
This library supports authenticating for Identity Server 4 out of the box. Some quirks:
153159
1. In order to enable `offline_access`, it must be passed in as a scope variable
154160
2. In order to revoke the access token, must sent client id in the method body of the request. This is not part of the OAuth spec.
155161

156-
### Google
162+
## Google
157163
Full support out of the box

index.js

+4-6
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ export default class AppAuth {
1717
}
1818

1919
authorize(scopes) {
20-
invariant(scopes, 'Scope error: please add at least one scope');
21-
invariant(scopes.length, 'Scope error: please add at least one scope');
20+
invariant(scopes && scopes.length, 'Scope error: please add at least one scope');
2221

2322
return RNAppAuth.authorize(
2423
this.config.issuer,
@@ -30,8 +29,7 @@ export default class AppAuth {
3029

3130
refresh(refreshToken, scopes) {
3231
invariant(refreshToken, 'Please pass in a refresh token');
33-
invariant(scopes, 'Scope error: please add at least one scope');
34-
invariant(scopes.length, 'Scope error: please add at least one scope');
32+
invariant(scopes && scopes.length, 'Scope error: please add at least one scope');
3533

3634
return RNAppAuth.refresh(
3735
this.config.issuer,
@@ -43,7 +41,7 @@ export default class AppAuth {
4341
}
4442

4543
async revokeToken(tokenToRevoke, sendClientId = false) {
46-
invariant(tokenToRevoke, 'Plese include the token to revoke');
44+
invariant(tokenToRevoke, 'Please include the token to revoke');
4745

4846
const response = await fetch(`${this.config.issuer}/.well-known/openid-configuration`);
4947
const openidConfig = await response.json();
@@ -65,7 +63,7 @@ export default class AppAuth {
6563
headers: {
6664
'Content-Type': 'application/x-www-form-urlencoded'
6765
},
68-
body: `token=${tokenToRevoke}${sendClientId ? `client_id=${this.config.clientId}` : ''}`
66+
body: `token=${tokenToRevoke}${sendClientId ? `&client_id=${this.config.clientId}` : ''}`
6967
}).catch(error => {
7068
throw new Error('Failed to revoke token', error);
7169
});

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"devDependencies": {
1919
"babel-eslint": "^8.0.2",
2020
"babel-jest": "^21.2.0",
21-
"babel-preset-es2015": "^6.24.1",
21+
"babel-preset-env": "^1.6.1",
2222
"eslint": "2.10.2",
2323
"eslint-config-formidable": "^3.0.0",
2424
"eslint-plugin-filenames": "^1.2.0",
@@ -27,5 +27,6 @@
2727
"jest": "^21.2.1",
2828
"react": "^16.1.1",
2929
"react-native": "^0.50.3"
30-
}
30+
},
31+
"dependencies": {}
3132
}

0 commit comments

Comments
 (0)