You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+97-47Lines changed: 97 additions & 47 deletions
Original file line number
Diff line number
Diff line change
@@ -3,27 +3,47 @@
3
3
4
4
# React Native App Auth
5
5
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
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:
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
endpoint to discover all auth endpoints automatically. It will be possible to extend the library
21
+
later to add custom configuration.
15
22
16
23
## Why you may want to use this library
17
24
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).
20
31
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.
22
35
23
36
## Supported methods
24
37
38
+
See [Usage](#usage) for example configurations, and the included [Example](Example) application for
39
+
a working sample.
40
+
25
41
### 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
+
27
47
```js
28
48
importAppAuthfrom'react-native-app-auth';
29
49
@@ -33,14 +53,19 @@ const result = await appAuth.authorize(scopes);
33
53
```
34
54
35
55
### 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
3.[Define openURL callback in AppDelegate](#define-openurl-callback-in-appdelegate)
92
123
93
124
#### Install native dependencies
94
125
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.
96
129
97
130
AppAuth supports three options for dependency management.
98
131
99
132
##### CocoaPods
100
133
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`:
103
136
104
137
pod 'AppAuth', '>= 0.91'
105
138
106
139
Then run `pod install`. Note that version 0.91 is the first of the library to support iOS 11.
107
140
108
141
##### Carthage
109
142
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`:
112
144
113
145
github "openid/AppAuth-iOS" "master"
114
146
115
147
Then run `carthage bootstrap`.
116
148
117
149
##### Static Library
118
150
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:
121
153
122
154
1. Create an XCode Workspace.
123
155
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").
129
160
130
161
#### Register redirect URL scheme
131
162
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:
133
165
134
166
```
135
167
<key>CFBundleURLTypes</key>
@@ -145,12 +177,15 @@ If you intend to support iOS 10 and older, you need to define the supported redi
145
177
</array>
146
178
```
147
179
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.
150
183
151
184
#### Define openURL callback in AppDelegate
152
185
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:
154
189
155
190
```diff
156
191
+ @protocol OIDAuthorizationFlowSession;
@@ -161,12 +196,16 @@ You need to have a property in your AppDelegate to hold the auth session, in ord
161
196
@end
162
197
```
163
198
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
+
165
203
```objective-c.
166
204
#import "AppAuth.h"
167
205
```
168
206
169
207
And in the bottom of the class, add the following handler:
208
+
170
209
```objective-c.
171
210
- (BOOL)application:(UIApplication *)app
172
211
openURL:(NSURL *)url
@@ -182,20 +221,25 @@ And in the bottom of the class, add the following handler:
182
221
### Android Setup
183
222
184
223
To setup the Android project, you need to perform two steps:
224
+
185
225
1.[Install Android support libraries](#install-android-support-libraries)
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:
191
233
192
234
1. Add the Google Maven repository in your `android/build.gradle`
193
235
```
194
236
repositories {
195
237
google()
196
238
}
197
239
```
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:
199
243
```
200
244
dependencies {
201
245
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-
210
254
211
255
#### Add redirect scheme manifest placeholder
212
256
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
+
214
261
```
215
262
android {
216
263
defaultConfig {
217
264
manifestPlaceholders = [
218
265
appAuthRedirectScheme: 'io.identityserver.demo'
219
-
]
266
+
]
220
267
}
221
268
}
222
269
```
@@ -250,8 +297,10 @@ See example configurations for different providers below.
250
297
### Identity Server 4
251
298
252
299
This library supports authenticating for Identity Server 4 out of the box. Some quirks:
300
+
253
301
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.
255
304
256
305
```js
257
306
// Note "offline_access" scope is required to get a refresh token
@@ -301,11 +350,12 @@ Thanks goes to these wonderful people
0 commit comments