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
3.[Define openURL callback in AppDelegate](#define-openurl-callback-in-appdelegate)
191
191
192
-
#### Install native dependencies
192
+
#####Install native dependencies
193
193
194
194
This library depends on the native [AppAuth-ios](https://github.com/openid/AppAuth-iOS) project. To
195
195
keep the React Native library agnostic of your dependency management method, the native libraries
196
196
are not distributed as part of the bridge.
197
197
198
198
AppAuth supports three options for dependency management.
199
199
200
-
##### CocoaPods
200
+
1.**CocoaPods**
201
201
202
-
With [CocoaPods](https://guides.cocoapods.org/using/getting-started.html), add the following line to
203
-
your `Podfile`:
202
+
With [CocoaPods](https://guides.cocoapods.org/using/getting-started.html), add the following line to
203
+
your `Podfile`:
204
204
205
-
pod 'AppAuth', '>= 0.91'
205
+
pod 'AppAuth', '>= 0.91'
206
206
207
-
Then run `pod install`. Note that version 0.91 is the first of the library to support iOS 11.
207
+
Then run `pod install`. Note that version 0.91 is the first of the library to support iOS 11.
208
208
209
-
##### Carthage
209
+
2.**Carthage**
210
210
211
-
With [Carthage](https://github.com/Carthage/Carthage), add the following line to your `Cartfile`:
211
+
With [Carthage](https://github.com/Carthage/Carthage), add the following line to your `Cartfile`:
212
212
213
-
github "openid/AppAuth-iOS" "master"
213
+
github "openid/AppAuth-iOS" "master"
214
214
215
-
Then run `carthage bootstrap`.
215
+
Then run `carthage bootstrap`.
216
216
217
-
##### Static Library
217
+
3.**Static Library**
218
218
219
-
You can also use [AppAuth-iOS](https://github.com/openid/AppAuth-iOS) as a static library. This
220
-
requires linking the library and your project and including the headers. Suggested configuration:
219
+
You can also use [AppAuth-iOS](https://github.com/openid/AppAuth-iOS) as a static library. This
220
+
requires linking the library and your project and including the headers. Suggested configuration:
221
221
222
-
1. Create an XCode Workspace.
223
-
2. Add `AppAuth.xcodeproj` to your Workspace.
224
-
3. Include libAppAuth as a linked library for your target (in the "General -> Linked Framework and
225
-
Libraries" section of your target).
226
-
4. Add `AppAuth-iOS/Source` to your search paths of your target ("Build Settings -> "Header Search
227
-
Paths").
222
+
1. Create an XCode Workspace.
223
+
2. Add `AppAuth.xcodeproj` to your Workspace.
224
+
3. Include libAppAuth as a linked library for your target (in the "General -> Linked Framework and
225
+
Libraries" section of your target).
226
+
4. Add `AppAuth-iOS/Source` to your search paths of your target ("Build Settings -> "Header Search
227
+
Paths").
228
228
229
-
#### Register redirect URL scheme
229
+
#####Register redirect URL scheme
230
230
231
231
If you intend to support iOS 10 and older, you need to define the supported redirect URL schemes in
232
232
your `Info.plist` as follows:
@@ -249,7 +249,7 @@ your `Info.plist` as follows:
249
249
*`CFBundleURLSchemes` is an array of URL schemes your app needs to handle. The scheme is the
250
250
beginning of your OAuth Redirect URL, up to the scheme separator (`:`) character.
251
251
252
-
#### Define openURL callback in AppDelegate
252
+
#####Define openURL callback in AppDelegate
253
253
254
254
You need to have a property in your AppDelegate to hold the auth session, in order to continue the
255
255
authorization flow from the redirect. To add this, open `AppDelegate.h` in your project and add the
@@ -266,15 +266,19 @@ following lines:
266
266
267
267
The authorization response URL is returned to the app via the iOS openURL app delegate method, so
268
268
you need to pipe this through to the current authorization session (created in the previous
269
-
instruction). To do this, open `AppDelegate.m` and add an import statement:
269
+
instruction).
270
270
271
-
```objective-c.
271
+
##### Add a current Authorization session
272
+
273
+
To do this, open `AppDelegate.m` and add an import statement:
274
+
275
+
```Objective-C
272
276
#import<AppAuth/AppAuth.h>
273
277
```
274
278
275
279
And in the bottom of the class, add the following handler:
276
280
277
-
```objective-c.
281
+
```Objective-C
278
282
- (BOOL)application:(UIApplication *)app
279
283
openURL:(NSURL *)url
280
284
options:(NSDictionary<NSString *, id> *)options {
@@ -286,14 +290,61 @@ And in the bottom of the class, add the following handler:
286
290
}
287
291
```
288
292
293
+
#### Integration of the library with a Swift iOS project
294
+
295
+
Until a better solution is available, we must use `react-native-app-auth` as a Static Library. This is due to the fact that the library is calling `AppDelegate.swift`.
296
+
297
+
1. Unlink `react-native-app-auth` from your projects `Libraries/`.
298
+
299
+
2. Manually copy the `RNAppAuth.h` and `RNAppAuth.m` files from the library folder in your `node_modules/` into your project folder.
300
+
301
+
3. In `RNAppAuth.m` add a new import:
302
+
```Objective-C
303
+
#import"<YouProjectName>-Swift.h"
304
+
```
305
+
306
+
4. In your project's `AppDelegate.swift`, expose your function to `Objective-C` by annotating the AppDelegate with:
307
+
```Swift
308
+
@objc(AppDelegate)
309
+
```
310
+
311
+
5. Add the following code just after the class declaration:
312
+
```Swift
313
+
var currentAuthorizationFlow: OIDAuthorizationFlowSession?
314
+
```
315
+
316
+
6. At the bottom of your class add the following code:
if currentAuthorizationFlow!.resumeAuthorizationFlow(with: url){
325
+
currentAuthorizationFlow = nil
326
+
return true
327
+
}
328
+
329
+
return false;
330
+
}
331
+
```
332
+
This is a translation of the following `Objective-C` code provided [above](#add-a-current-authorization-session)
333
+
334
+
**Warning:**
335
+
336
+
You may need to perform Step 4 and compile your project so that the hidden bridging header file is created. If this file is not created and you follow the rest of the steps then you may fall into a chicken before the egg problem where the project is failing to build because of the missing header file and the header file won't be created because the build is failing.
337
+
338
+
339
+
289
340
### Android Setup
290
341
291
342
To setup the Android project, you need to perform two steps:
292
343
293
344
1. [Install Android support libraries](#install-android-support-libraries)
0 commit comments