@@ -21,7 +21,7 @@ This library _should_ support any OAuth provider that implements the
21
21
22
22
We only support the [ Authorization Code Flow] ( https://oauth.net/2/grant-types/authorization-code/ ) .
23
23
24
- ### Tested OpenID providers
24
+ ## Tested OpenID providers
25
25
26
26
These providers are OpenID compliant, which means you can use [ autodiscovery] ( https://openid.net/specs/openid-connect-discovery-1_0.html ) .
27
27
@@ -36,7 +36,7 @@ These providers are OpenID compliant, which means you can use [autodiscovery](ht
36
36
- [ AWS Cognito] ( https://eu-west-1.console.aws.amazon.com/cognito ) ([ Example configuration] ( ./docs/config-examples/aws-cognito.md ) )
37
37
- [ Asgardeo] ( https://asgardeo.io ) ([ Example configuration] ( ./docs/config-examples/asgardeo.md ) )
38
38
39
- ### Tested OAuth2 providers
39
+ ## Tested OAuth2 providers
40
40
41
41
These providers implement the OAuth2 spec, but are not OpenID providers, which means you must configure the authorization and token endpoints yourself.
42
42
@@ -261,10 +261,15 @@ This is the result from the auth server
261
261
262
262
## Getting started
263
263
264
+ ``` sh
265
+ yarn add react-native-app-auth
266
+ ```
267
+ Or
264
268
``` sh
265
269
npm install react-native-app-auth --save
266
270
```
267
271
272
+
268
273
## Setup
269
274
270
275
### iOS Setup
@@ -275,7 +280,7 @@ To setup the iOS project, you need to perform three steps:
275
280
2 . [ Register redirect URL scheme] ( #register-redirect-url-scheme )
276
281
3 . [ Define openURL callback in AppDelegate] ( #define-openurl-callback-in-appdelegate )
277
282
278
- ##### Install native dependencies
283
+ #### Install native dependencies
279
284
280
285
This library depends on the native [ AppAuth-ios] ( https://github.com/openid/AppAuth-iOS ) project. To
281
286
keep the React Native library agnostic of your dependency management method, the native libraries
@@ -314,7 +319,7 @@ AppAuth supports three options for dependency management.
314
319
4. Add ` AppAuth-iOS/Source` to your search paths of your target (" Build Settings -> " Header Search
315
320
Paths" ).
316
321
317
- ##### Register redirect URL scheme
322
+ #### Register redirect URL scheme
318
323
319
324
If you intend to support iOS 10 and older, you need to define the supported redirect URL schemes in
320
325
your ` Info.plist` as follows:
@@ -338,7 +343,7 @@ your `Info.plist` as follows:
338
343
beginning of your OAuth Redirect URL, up to the scheme separator (` :` ) character. E.g. if your redirect uri
339
344
is ` com.myapp://oauth` , then the url scheme will is ` com.myapp` .
340
345
341
- ##### Define openURL callback in AppDelegate
346
+ #### Define openURL callback in AppDelegate
342
347
343
348
You need to retain the auth session, in order to continue the
344
349
authorization flow from the redirect. Follow these steps:
@@ -347,6 +352,54 @@ authorization flow from the redirect. Follow these steps:
347
352
Furthermore, ` RNAppAuth` expects the delegate instance to conform to the protocol ` RNAppAuthAuthorizationFlowManager` .
348
353
Make ` AppDelegate` conform to ` RNAppAuthAuthorizationFlowManager` with the following changes to ` AppDelegate.h` :
349
354
355
+ ##### For react-native >= 0.68
356
+ Example setup can be see in the [Example app](./Example/ios)
357
+
358
+ ` ` ` diff
359
+ + # import <React/RCTLinkingManager.h>
360
+ + #import "RNAppAuthAuthorizationFlowManager.h"
361
+
362
+ - @interface AppDelegate : RCTAppDelegate
363
+ + @interface AppDelegate : RCTAppDelegate <RNAppAuthAuthorizationFlowManager>
364
+
365
+ + @property(nonatomic, weak) id<RNAppAuthAuthorizationFlowManagerDelegate> authorizationFlowManagerDelegate;
366
+ ` ` `
367
+
368
+ Add the following code to ` AppDelegate.mm` to support React Navigation deep linking and overriding browser behavior in the authorization process
369
+
370
+ ` ` ` diff
371
+ + - (BOOL) application: (UIApplication * )application
372
+ + openURL: (NSURL * )url
373
+ + options: (NSDictionary< UIApplicationOpenURLOptionsKey, id> * ) options
374
+ + {
375
+ + if ([self.authorizationFlowManagerDelegate resumeExternalUserAgentFlowWithURL:url]) {
376
+ + return YES;
377
+ + }
378
+ + return [RCTLinkingManager application:application openURL:url options:options];
379
+ + }
380
+ ` ` `
381
+
382
+ If you want to support universal links, add the following to ` AppDelegate.mm` under ` continueUserActivity`
383
+
384
+ ` ` ` diff
385
+ + - (BOOL) application: (UIApplication * ) application
386
+ + continueUserActivity: (nonnull NSUserActivity * )userActivity
387
+ + restorationHandler: (nonnull void (^)(NSArray< id< UIUserActivityRestoring>> * _Nullable))restorationHandler
388
+ + {
389
+ + if ([userActivity.activityType isEqualToString:NSUserActivityTypeBrowsingWeb]) {
390
+ + if (self.authorizationFlowManagerDelegate) {
391
+ + BOOL resumableAuth = [self.authorizationFlowManagerDelegate resumeExternalUserAgentFlowWithURL:userActivity.webpageURL];
392
+ + if (resumableAuth) {
393
+ + return YES;
394
+ + }
395
+ + }
396
+ + }
397
+ + return [RCTLinkingManager application:application continueUserActivity:userActivity restorationHandler:restorationHandler];
398
+ + }
399
+ ` ` `
400
+
401
+ # #### For react-native < 0.68
402
+
350
403
` ` ` diff
351
404
+ # import "RNAppAuthAuthorizationFlowManager.h"
352
405
0 commit comments