Skip to content

Commit 7bf5bb1

Browse files
committed
Add link to example in the main README
1 parent 931654c commit 7bf5bb1

File tree

1 file changed

+97
-47
lines changed

1 file changed

+97
-47
lines changed

README.md

Lines changed: 97 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,47 @@
33

44
# React Native App Auth
55

6-
React Native bridge for [AppAuth-iOS](https://github.com/openid/AppAuth-iOS) and [AppAuth-Android](https://github.com/openid/AppAuth-Android) SDKS for communicating with
7-
[OAuth 2.0](https://tools.ietf.org/html/rfc6749) and [OpenID Connect](http://openid.net/specs/openid-connect-core-1_0.html) providers.
6+
React Native bridge for [AppAuth-iOS](https://github.com/openid/AppAuth-iOS) and
7+
[AppAuth-Android](https://github.com/openid/AppAuth-Android) SDKS for communicating with
8+
[OAuth 2.0](https://tools.ietf.org/html/rfc6749) and
9+
[OpenID Connect](http://openid.net/specs/openid-connect-core-1_0.html) providers.
810

9-
This 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:
11+
This library _should_ support any OAuth provider that implements the
12+
[OAuth2 spec](https://tools.ietf.org/html/rfc6749#section-2.2) and it has been tested with:
1013

11-
- [Identity Server4](https://demo.identityserver.io/) ([Example configuration](#identity-server-4))
12-
- [Google](https://developers.google.com/identity/protocols/OAuth2) ([Example configuration](#google))
14+
* [Identity Server4](https://demo.identityserver.io/) ([Example configuration](#identity-server-4))
15+
* [Google](https://developers.google.com/identity/protocols/OAuth2)
16+
([Example configuration](#google))
1317

14-
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.
18+
The library uses auto-discovery which mean it relies on the the
19+
[.well-known/openid-configuration](https://openid.net/specs/openid-connect-discovery-1_0.html)
20+
endpoint to discover all auth endpoints automatically. It will be possible to extend the library
21+
later to add custom configuration.
1522

1623
## Why you may want to use this library
1724

18-
AppAuth is a mature OAuth client implementation that follows the best practices set out in [RFC 8252 - OAuth 2.0 for Native Apps](https://tools.ietf.org/html/rfc8252)
19-
including using `SFAuthenticationSession` and `SFSafariViewController` on iOS, and [Custom Tabs](http://developer.android.com/tools/support-library/features.html#custom-tabs) on Android. `WebView`s are explicitly *not* supported due to the security and usability reasons explained in [Section 8.12 of RFC 8252](https://tools.ietf.org/html/rfc8252#section-8.12).
25+
AppAuth is a mature OAuth client implementation that follows the best practices set out in
26+
[RFC 8252 - OAuth 2.0 for Native Apps](https://tools.ietf.org/html/rfc8252) including using
27+
`SFAuthenticationSession` and `SFSafariViewController` on iOS, and
28+
[Custom Tabs](http://developer.android.com/tools/support-library/features.html#custom-tabs) on
29+
Android. `WebView`s are explicitly _not_ supported due to the security and usability reasons
30+
explained in [Section 8.12 of RFC 8252](https://tools.ietf.org/html/rfc8252#section-8.12).
2031

21-
AppAuth also supports the [PKCE](https://tools.ietf.org/html/rfc7636) ("Pixy") extension to OAuth which was created to secure authorization codes in public clients when custom URI scheme redirects are used.
32+
AppAuth also supports the [PKCE](https://tools.ietf.org/html/rfc7636) ("Pixy") extension to OAuth
33+
which was created to secure authorization codes in public clients when custom URI scheme redirects
34+
are used.
2235

2336
## Supported methods
2437

38+
See [Usage](#usage) for example configurations, and the included [Example](Example) application for
39+
a working sample.
40+
2541
### authorize
26-
This is the main function to use for authentication. Invoking 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.
42+
43+
This is the main function to use for authentication. Invoking this function will do the whole login
44+
flow and returns the access token, refresh token and access token expiry date when successful, or it
45+
throws an error when not successful.
46+
2747
```js
2848
import AppAuth from 'react-native-app-auth';
2949

@@ -33,14 +53,19 @@ const result = await appAuth.authorize(scopes);
3353
```
3454

3555
### refresh
36-
This method will refresh the accessToken using the refreshToken. Some auth providers will also give you a new refreshToken
56+
57+
This method will refresh the accessToken using the refreshToken. Some auth providers will also give
58+
you a new refreshToken
59+
3760
```js
3861
const result = await appAuth.refresh(refreshToken, scopes);
3962
// returns accessToken, accessTokenExpirationDate and (maybe) refreshToken
4063
```
4164

4265
### revokeToken
66+
4367
This method will revoke a token. The tokenToRevoke can be either an accessToken or a refreshToken
68+
4469
```js
4570
// note, sendClientId=true will only be required when using IdentityServer
4671
const result = await appAuth.revokeToken(tokenToRevoke, sendClientId);
@@ -55,81 +80,88 @@ react-native link react-native-app-auth
5580

5681
**Then follow the [Setup](#setup) steps to configure the native iOS and Android projects.**
5782

58-
If you are not using `react-native link`, perform the [Manual installation](#manual-installation) steps instead.
83+
If you are not using `react-native link`, perform the [Manual installation](#manual-installation)
84+
steps instead.
5985

6086
### Manual installation
6187

6288
#### iOS
6389

64-
1. In XCode, in the project navigator, right click `Libraries``Add Files to [your project's name]`
90+
1. In XCode, in the project navigator, right click `Libraries` ➜ `Add Files to [your project's
91+
name]`
6592
2. Go to `node_modules``react-native-app-auth` and add `RNAppAuth.xcodeproj`
66-
3. In XCode, in the project navigator, select your project. Add `libRNAppAuth.a` to your project's `Build Phases``Link Binary With Libraries`
93+
3. In XCode, in the project navigator, select your project. Add `libRNAppAuth.a` to your project's
94+
`Build Phases``Link Binary With Libraries`
6795
4. Run your project (`Cmd+R`)<
6896

6997
#### Android
7098

7199
1. Open up `android/app/src/main/java/[...]/MainActivity.java`
72-
- Add `import com.reactlibrary.RNAppAuthPackage;` to the imports at the top of the file
73-
- Add `new RNAppAuthPackage()` to the list returned by the `getPackages()` method
100+
101+
* Add `import com.reactlibrary.RNAppAuthPackage;` to the imports at the top of the file
102+
* Add `new RNAppAuthPackage()` to the list returned by the `getPackages()` method
103+
74104
2. Append the following lines to `android/settings.gradle`:
75-
```
76-
include ':react-native-app-auth'
77-
project(':react-native-app-auth').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-app-auth/android')
78-
```
105+
```
106+
include ':react-native-app-auth'
107+
project(':react-native-app-auth').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-app-auth/android')
108+
```
79109
3. Insert the following lines inside the dependencies block in `android/app/build.gradle`:
80-
```
81-
compile project(':react-native-app-auth')
82-
```
110+
```
111+
compile project(':react-native-app-auth')
112+
```
83113

84114
## Setup
85115

86116
### iOS Setup
87117

88118
To setup the iOS project, you need to perform three steps:
119+
89120
1. [Install native dependencies](#install-native-dependencies)
90121
2. [Register redirect URL scheme](#register-redirect-url-scheme)
91122
3. [Define openURL callback in AppDelegate](#define-openurl-callback-in-appdelegate)
92123

93124
#### Install native dependencies
94125

95-
This library depends on the native [AppAuth-ios](https://github.com/openid/AppAuth-iOS) project. To keep the React Native library agnostic of your dependency management method, the native libraries are not distributed as part of the bridge.
126+
This library depends on the native [AppAuth-ios](https://github.com/openid/AppAuth-iOS) project. To
127+
keep the React Native library agnostic of your dependency management method, the native libraries
128+
are not distributed as part of the bridge.
96129

97130
AppAuth supports three options for dependency management.
98131

99132
##### CocoaPods
100133

101-
With [CocoaPods](https://guides.cocoapods.org/using/getting-started.html),
102-
add the following line to your `Podfile`:
134+
With [CocoaPods](https://guides.cocoapods.org/using/getting-started.html), add the following line to
135+
your `Podfile`:
103136

104137
pod 'AppAuth', '>= 0.91'
105138

106139
Then run `pod install`. Note that version 0.91 is the first of the library to support iOS 11.
107140

108141
##### Carthage
109142

110-
With [Carthage](https://github.com/Carthage/Carthage), add the following
111-
line to your `Cartfile`:
143+
With [Carthage](https://github.com/Carthage/Carthage), add the following line to your `Cartfile`:
112144

113145
github "openid/AppAuth-iOS" "master"
114146

115147
Then run `carthage bootstrap`.
116148

117149
##### Static Library
118150

119-
You can also use [AppAuth-iOS](https://github.com/openid/AppAuth-iOS) as a static library. This requires linking the library
120-
and your project and including the headers. Suggested configuration:
151+
You can also use [AppAuth-iOS](https://github.com/openid/AppAuth-iOS) as a static library. This
152+
requires linking the library and your project and including the headers. Suggested configuration:
121153

122154
1. Create an XCode Workspace.
123155
2. Add `AppAuth.xcodeproj` to your Workspace.
124-
3. Include libAppAuth as a linked library for your target (in the "General ->
125-
Linked Framework and Libraries" section of your target).
126-
4. Add `AppAuth-iOS/Source` to your search paths of your target ("Build Settings ->
127-
"Header Search Paths").
128-
156+
3. Include libAppAuth as a linked library for your target (in the "General -> Linked Framework and
157+
Libraries" section of your target).
158+
4. Add `AppAuth-iOS/Source` to your search paths of your target ("Build Settings -> "Header Search
159+
Paths").
129160

130161
#### Register redirect URL scheme
131162

132-
If you intend to support iOS 10 and older, you need to define the supported redirect URL schemes in your `Info.plist` as follows:
163+
If you intend to support iOS 10 and older, you need to define the supported redirect URL schemes in
164+
your `Info.plist` as follows:
133165

134166
```
135167
<key>CFBundleURLTypes</key>
@@ -145,12 +177,15 @@ If you intend to support iOS 10 and older, you need to define the supported redi
145177
</array>
146178
```
147179

148-
- `CFBundleURLName` is any globally unique string. A common practice is to use your app identifier.
149-
- `CFBundleURLSchemes` is an array of URL schemes your app needs to handle. The scheme is the beginning of your OAuth Redirect URL, up to the scheme separator (`:`) character.
180+
* `CFBundleURLName` is any globally unique string. A common practice is to use your app identifier.
181+
* `CFBundleURLSchemes` is an array of URL schemes your app needs to handle. The scheme is the
182+
beginning of your OAuth Redirect URL, up to the scheme separator (`:`) character.
150183

151184
#### Define openURL callback in AppDelegate
152185

153-
You need to have a property in your AppDelegate to hold the auth session, in order to continue the authorization flow from the redirect. To add this, open `AppDelegate.h` in your project and add the following lines:
186+
You need to have a property in your AppDelegate to hold the auth session, in order to continue the
187+
authorization flow from the redirect. To add this, open `AppDelegate.h` in your project and add the
188+
following lines:
154189

155190
```diff
156191
+ @protocol OIDAuthorizationFlowSession;
@@ -161,12 +196,16 @@ You need to have a property in your AppDelegate to hold the auth session, in ord
161196
@end
162197
```
163198

164-
The authorization response URL is returned to the app via the iOS openURL app delegate method, so you need to pipe this through to the current authorization session (created in the previous instruction). To do this, open `AppDelegate.m` and add an import statement:
199+
The authorization response URL is returned to the app via the iOS openURL app delegate method, so
200+
you need to pipe this through to the current authorization session (created in the previous
201+
instruction). To do this, open `AppDelegate.m` and add an import statement:
202+
165203
```objective-c.
166204
#import "AppAuth.h"
167205
```
168206

169207
And in the bottom of the class, add the following handler:
208+
170209
```objective-c.
171210
- (BOOL)application:(UIApplication *)app
172211
openURL:(NSURL *)url
@@ -182,20 +221,25 @@ And in the bottom of the class, add the following handler:
182221
### Android Setup
183222

184223
To setup the Android project, you need to perform two steps:
224+
185225
1. [Install Android support libraries](#install-android-support-libraries)
186226
2. [Add redirect scheme manifest placeholder](#add-redirect-scheme-manifest-placeholder)
187227

188228
#### Install Android support libraries
189229

190-
This library depends on the [AppAuth-Android](https://github.com/openid/AppAuth-android) project. The native dependencies for Android are automatically installed by Gradle, but you need to add the correct Android Support library version to your project:
230+
This library depends on the [AppAuth-Android](https://github.com/openid/AppAuth-android) project.
231+
The native dependencies for Android are automatically installed by Gradle, but you need to add the
232+
correct Android Support library version to your project:
191233

192234
1. Add the Google Maven repository in your `android/build.gradle`
193235
```
194236
repositories {
195237
google()
196238
}
197239
```
198-
2. Make sure the appcompat version in `android/app/build.gradle` matches the one expected by AppAuth. If you generated your project using `react-native init`, you may have an older version of the appcompat libraries and need to upgdrade:
240+
2. Make sure the appcompat version in `android/app/build.gradle` matches the one expected by
241+
AppAuth. If you generated your project using `react-native init`, you may have an older version
242+
of the appcompat libraries and need to upgdrade:
199243
```
200244
dependencies {
201245
compile "com.android.support:appcompat-v7:25.3.1"
@@ -210,13 +254,16 @@ This library depends on the [AppAuth-Android](https://github.com/openid/AppAuth-
210254

211255
#### Add redirect scheme manifest placeholder
212256

213-
To [capture the authorization redirect](https://github.com/openid/AppAuth-android#capturing-the-authorization-redirect), add the following property to the defaultConfig in `android/app/build.gradle`:
257+
To
258+
[capture the authorization redirect](https://github.com/openid/AppAuth-android#capturing-the-authorization-redirect),
259+
add the following property to the defaultConfig in `android/app/build.gradle`:
260+
214261
```
215262
android {
216263
defaultConfig {
217264
manifestPlaceholders = [
218265
appAuthRedirectScheme: 'io.identityserver.demo'
219-
]
266+
]
220267
}
221268
}
222269
```
@@ -250,8 +297,10 @@ See example configurations for different providers below.
250297
### Identity Server 4
251298

252299
This library supports authenticating for Identity Server 4 out of the box. Some quirks:
300+
253301
1. In order to enable refresh tokens, `offline_access` must be passed in as a scope variable
254-
2. In order to revoke the access token, we must sent client id in the method body of the request. This is not part of the OAuth spec.
302+
2. In order to revoke the access token, we must sent client id in the method body of the request.
303+
This is not part of the OAuth spec.
255304

256305
```js
257306
// Note "offline_access" scope is required to get a refresh token
@@ -301,11 +350,12 @@ Thanks goes to these wonderful people
301350
([emoji key](https://github.com/kentcdodds/all-contributors#emoji-key)):
302351

303352
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
353+
304354
<!-- prettier-ignore -->
305355
| [<img src="https://avatars0.githubusercontent.com/u/6534400?v=4" width="100px;"/><br /><sub><b>Kadi Kraman</b></sub>](https://github.com/kadikraman)<br />[💻](https://github.com/FormidableLabs/react-native-app-auth/commits?author=kadikraman "Code") [📖](https://github.com/FormidableLabs/react-native-app-auth/commits?author=kadikraman "Documentation") [🚇](#infra-kadikraman "Infrastructure (Hosting, Build-Tools, etc)") [⚠️](https://github.com/FormidableLabs/react-native-app-auth/commits?author=kadikraman "Tests") [👀](#review-kadikraman "Reviewed Pull Requests") [💡](#example-kadikraman "Examples") | [<img src="https://avatars1.githubusercontent.com/u/1203949?v=4" width="100px;"/><br /><sub><b>Jani Eväkallio</b></sub>](https://twitter.com/jevakallio)<br />[💡](#example-jevakallio "Examples") [📖](https://github.com/FormidableLabs/react-native-app-auth/commits?author=jevakallio "Documentation") [⚠️](https://github.com/FormidableLabs/react-native-app-auth/commits?author=jevakallio "Tests") [👀](#review-jevakallio "Reviewed Pull Requests") [🤔](#ideas-jevakallio "Ideas, Planning, & Feedback") | [<img src="https://avatars0.githubusercontent.com/u/2041385?v=4" width="100px;"/><br /><sub><b>Phil Plückthun</b></sub>](https://twitter.com/_philpl)<br />[📖](https://github.com/FormidableLabs/react-native-app-auth/commits?author=philpl "Documentation") [👀](#review-philpl "Reviewed Pull Requests") [🤔](#ideas-philpl "Ideas, Planning, & Feedback") | [<img src="https://avatars1.githubusercontent.com/u/4206028?v=4" width="100px;"/><br /><sub><b>Imran Sulemanji</b></sub>](https://github.com/imranolas)<br />[🤔](#ideas-imranolas "Ideas, Planning, & Feedback") [👀](#review-imranolas "Reviewed Pull Requests") | [<img src="https://avatars3.githubusercontent.com/u/2393035?v=4" width="100px;"/><br /><sub><b>JP</b></sub>](http://twitter.com/jpdriver)<br />[🤔](#ideas-jpdriver "Ideas, Planning, & Feedback") [👀](#review-jpdriver "Reviewed Pull Requests") | [<img src="https://avatars2.githubusercontent.com/u/6714912?v=4" width="100px;"/><br /><sub><b>Matt Cubitt</b></sub>](https://github.com/mattcubitt)<br />[🤔](#ideas-mattcubitt "Ideas, Planning, & Feedback") [👀](#review-mattcubitt "Reviewed Pull Requests") |
306356
| :---: | :---: | :---: | :---: | :---: | :---: |
357+
307358
<!-- ALL-CONTRIBUTORS-LIST:END -->
308359

309-
This project follows the
310-
[all-contributors](https://github.com/kentcdodds/all-contributors)
360+
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors)
311361
specification. Contributions of any kind are welcome!

0 commit comments

Comments
 (0)