add presenting view controller parameter

This commit is contained in:
Jay Moore
2014-09-10 08:18:50 -04:00
parent d28f0ddfdd
commit 459ea6d7a6
4 changed files with 27 additions and 4 deletions
@@ -25,7 +25,7 @@
@interface UPAuthViewController : UINavigationController
- (id)initWithURL:(NSURL *)url delegate:(id<UPAuthViewControllerDelegate>)delegate;
- (void)show;
- (void)presentWithViewController:(UIViewController*)presentingViewController;
@end
#endif
@@ -80,9 +80,13 @@
self.webView.backgroundColor = [UIColor whiteColor];
}
- (void)show
- (void)presentWithViewController:(UIViewController*)presentingViewController;
{
[self.rootViewController presentViewController:self animated:YES completion:^{
if (presentingViewController == nil) {
presentingViewController = self.rootViewController;
}
[presentingViewController presentViewController:self animated:YES completion:^{
[self.webView loadRequest:[NSURLRequest requestWithURL:self.authURL]];
}];
}
+14
View File
@@ -178,6 +178,20 @@ typedef void(^UPPlatformRequestCompletion)(UPURLRequest *request, UPURLResponse
*/
- (void)startSessionWithClientID:(NSString *)clientID clientSecret:(NSString *)clientSecret authScope:(UPPlatformAuthScope)authScope redirectURI:(NSString *)redirectURI completion:(UPPlatformSessionCompletion)completion;
/**
* Starts a user's session.
*
* This will present a UIWebView to perform the OAuth authentication flow, taking care of getting the access token for HTTP requests.
*
* @param clientID The client ID provided during application signup.
* @param clientSecret The client secret provided during application signup.
* @param authScope Options to request specific auth scopes during authentication. Defaults to UPPlatformAuthScopeBasicRead.
* @param redirectURI An alternate redirect URI used during authentication. This is not common.
* @param presentingViewController View controller to present authentication view controller. Uses the window root view controller if nil.
* @param completion The session completion block.
*/
- (void)startSessionWithClientID:(NSString *)clientID clientSecret:(NSString *)clientSecret authScope:(UPPlatformAuthScope)authScope redirectURI:(NSString *)redirectURI presentingViewController:(UIViewController*)presentingViewController completion:(UPPlatformSessionCompletion)completion;
#endif
/**
+6 -1
View File
@@ -302,6 +302,11 @@ decisionListener:(id<WebPolicyDecisionListener>)listener
}
- (void)startSessionWithClientID:(NSString *)clientID clientSecret:(NSString *)clientSecret authScope:(UPPlatformAuthScope)authScope redirectURI:(NSString *)redirectURI completion:(UPPlatformSessionCompletion)completion
{
[self startSessionWithClientID:clientID clientSecret:clientSecret authScope:authScope redirectURI:redirectURI presentingViewController:nil completion:completion];
}
- (void)startSessionWithClientID:(NSString *)clientID clientSecret:(NSString *)clientSecret authScope:(UPPlatformAuthScope)authScope redirectURI:(NSString *)redirectURI presentingViewController:(UIViewController*)presentingViewController completion:(UPPlatformSessionCompletion)completion
{
self.sessionCompletion = completion;
self.clientID = clientID;
@@ -328,7 +333,7 @@ decisionListener:(id<WebPolicyDecisionListener>)listener
NSMutableString *authURLString = [NSMutableString stringWithFormat:@"%@/auth/oauth2/auth?response_type=code&client_id=%@&scope=%@&redirect_uri=%@", [UPPlatform basePlatformURL], self.clientID, [self stringFromAuthScope:authScope], redirectURI];
self.authViewController = [[UPAuthViewController alloc] initWithURL:[NSURL URLWithString:authURLString] delegate:self];
[self.authViewController show];
[self.authViewController presentWithViewController:presentingViewController];
}
#endif