Skip to content

Commit dd8dd75

Browse files
author
hakonk
committed
kaizen: add more docs
1 parent 16a6efa commit dd8dd75

File tree

1 file changed

+25
-29
lines changed

1 file changed

+25
-29
lines changed

README.md

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -251,43 +251,39 @@ your `Info.plist` as follows:
251251

252252
##### Define openURL callback in AppDelegate
253253

254-
You need to have a property in your AppDelegate to hold the auth session, in order to continue the
255-
authorization flow from the redirect. To add this, open `AppDelegate.h` in your project and add the
256-
following lines:
254+
You need to retain the auth session, in order to continue the
255+
authorization flow from the redirect. Follow these steps:
257256

258-
```diff
259-
+ @protocol OIDAuthorizationFlowSession;
257+
`RNAppAuth` will call on the given app's delegate via `[UIApplication sharedApplication].delegate`.
258+
Furthermore, `RNAppAuth` expects the delegate instance to conform to the protocol `RNAppAuthAuthorizationFlowManager`.
259+
Make `AppDelegate` conform to `RNAppAuthAuthorizationFlowManager`:
260260

261-
@interface AppDelegate : UIResponder <UIApplicationDelegate>
262-
+ @property(nonatomic, strong, nullable) id<OIDAuthorizationFlowSession> currentAuthorizationFlow;
263-
@property (nonatomic, strong) UIWindow *window;
264-
@end
261+
```diff
262+
+ @interface AppDelegate()<RNAppAuthAuthorizationFlowManager> {
263+
+ id <OIDAuthorizationFlowSession> _currentSession;
264+
+ }
265+
+ @end
265266
```
266267

267-
The authorization response URL is returned to the app via the iOS openURL app delegate method, so
268-
you need to pipe this through to the current authorization session (created in the previous
269-
instruction).
270-
271-
##### Add a current Authorization session
272-
273-
To do this, open `AppDelegate.m` and add an import statement:
268+
Implement the required method of `RNAppAuthAuthorizationFlowManager` in `AppDelegate`:
274269

275-
```Objective-C
276-
#import <AppAuth/AppAuth.h>
270+
```diff
271+
+ -(void)setCurrentAuthorizationFlowSession:(id<OIDAuthorizationFlowSession>)session {
272+
+ // retain session for further use
273+
+ _currentSession = session;
274+
+ }
277275
```
278276

279-
And in the bottom of the class, add the following handler:
277+
The authorization response URL is returned to the app via the iOS openURL app delegate method, so
278+
you need to pipe this through to the current authorization session (created in the previous
279+
instruction). Thus, implement the following method from `UIApplicationDelegate` in `AppDelegate`:
280280

281-
```Objective-C
282-
- (BOOL)application:(UIApplication *)app
283-
openURL:(NSURL *)url
284-
options:(NSDictionary<NSString *, id> *)options {
285-
if ([_currentAuthorizationFlow resumeAuthorizationFlowWithURL:url]) {
286-
_currentAuthorizationFlow = nil;
287-
return YES;
288-
}
289-
return NO;
290-
}
281+
```diff
282+
+ - (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *, id> *)options {
283+
+ BOOL shouldOpenUrl = [_currentSession resumeAuthorizationFlowWithURL:url];
284+
+ _currentSession = nil;
285+
+ return shouldOpenUrl;
286+
+ }
291287
```
292288

293289
#### Integration of the library with a Swift iOS project

0 commit comments

Comments
 (0)