| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 6 #error "This file requires ARC support." | |
| 7 #endif | |
| 8 | |
| 9 // TODO (aboone) This include is for The Google Toolbox for Mac OAuth 2 | |
| 10 // Controllers https://code.google.com/p/gtm-oauth2/ This may need to be added | |
| 11 // as a third-party or locate the proper project in Chromium. | |
| 12 #import "GTMOAuth2ViewControllerTouch.h" | |
| 13 | |
| 14 #include "google_apis/google_api_keys.h" | |
| 15 #import "remoting/ios/authorize.h" | |
| 16 #include "remoting/base/service_urls.h" | |
| 17 // TODO (aboone) Pulling in some service values from the host side. The cc's | |
| 18 // are also compiled as part of this project because the target remoting_host | |
| 19 // does not build on iOS right now. | |
| 20 #include "remoting/host/setup/oauth_helper.h" | |
| 21 | |
| 22 namespace { | |
| 23 static NSString* const kKeychainItemName = @"Google Chromoting iOS"; | |
| 24 | |
| 25 NSString* ClientId() { | |
| 26 return | |
| 27 [NSString stringWithUTF8String:google_apis::GetOAuth2ClientID( | |
| 28 google_apis::CLIENT_REMOTING).c_str()]; | |
| 29 } | |
| 30 | |
| 31 NSString* ClientSecret() { | |
| 32 return | |
| 33 [NSString stringWithUTF8String:google_apis::GetOAuth2ClientSecret( | |
| 34 google_apis::CLIENT_REMOTING).c_str()]; | |
| 35 } | |
| 36 | |
| 37 NSString* Scopes() { | |
| 38 return [NSString stringWithUTF8String:remoting::GetOauthScope().c_str()]; | |
| 39 } | |
| 40 | |
| 41 NSMutableString* HostURL() { | |
| 42 return | |
| 43 [NSMutableString stringWithUTF8String:remoting::ServiceUrls::GetInstance() | |
| 44 ->directory_hosts_url() | |
| 45 .c_str()]; | |
| 46 } | |
| 47 | |
| 48 NSString* APIKey() { | |
| 49 return [NSString stringWithUTF8String:google_apis::GetAPIKey().c_str()]; | |
| 50 } | |
| 51 | |
| 52 } // namespace | |
| 53 | |
| 54 @implementation Authorize | |
| 55 | |
| 56 + (GTMOAuth2Authentication*)getAnyExistingAuthorization { | |
| 57 // Ensure the google_apis lib has keys | |
| 58 // If this check fails then google_apis was not built right | |
| 59 // TODO (aboone) For now we specify the preprocessor macros for | |
| 60 // GOOGLE_CLIENT_SECRET_REMOTING and GOOGLE_CLIENT_ID_REMOTING when building | |
| 61 // the google_apis target. The values may be developer specific, and should | |
| 62 // be well know to the project staff. | |
| 63 // See http://www.chromium.org/developers/how-tos/api-keys for more general | |
| 64 // information. | |
| 65 DCHECK(![ClientId() isEqualToString:@"dummytoken"]); | |
| 66 | |
| 67 return [GTMOAuth2ViewControllerTouch | |
| 68 authForGoogleFromKeychainForName:kKeychainItemName | |
| 69 clientID:ClientId() | |
| 70 clientSecret:ClientSecret()]; | |
| 71 } | |
| 72 | |
| 73 + (void)beginRequest:(GTMOAuth2Authentication*)authReq | |
| 74 delegate:(id)delegate | |
| 75 didFinishSelector:(SEL)sel { | |
| 76 // Build request URL using API HTTP endpoint, and our api key | |
| 77 NSMutableString* hostsUrl = HostURL(); | |
| 78 [hostsUrl appendString:@"?key="]; | |
| 79 [hostsUrl appendString:APIKey()]; | |
| 80 | |
| 81 NSMutableURLRequest* theRequest = | |
| 82 [NSMutableURLRequest requestWithURL:[NSURL URLWithString:hostsUrl]]; | |
| 83 | |
| 84 // Add scopes if needed | |
| 85 NSString* scope = authReq.scope; | |
| 86 | |
| 87 if ([scope rangeOfString:Scopes()].location == NSNotFound) { | |
| 88 scope = [GTMOAuth2Authentication scopeWithStrings:scope, Scopes(), nil]; | |
| 89 authReq.scope = scope; | |
| 90 } | |
| 91 | |
| 92 // Execute request async | |
| 93 [authReq authorizeRequest:theRequest delegate:delegate didFinishSelector:sel]; | |
| 94 } | |
| 95 | |
| 96 + (void)appendCredentials:(NSMutableURLRequest*)request { | |
| 97 // Add credentials for service | |
| 98 [request addValue:ClientId() forHTTPHeaderField:@"client_id"]; | |
| 99 [request addValue:ClientSecret() forHTTPHeaderField:@"client_secret"]; | |
| 100 } | |
| 101 | |
| 102 + (UINavigationController*)createLoginController:(id)delegate | |
| 103 finishedSelector:(SEL)finishedSelector { | |
| 104 [GTMOAuth2ViewControllerTouch | |
| 105 removeAuthFromKeychainForName:kKeychainItemName]; | |
| 106 | |
| 107 // When the sign in is complete a http redirection occurs, and the | |
| 108 // user would see the output. We do not want the user to notice this | |
| 109 // transition. Wrapping the oAuth2 Controller in a | |
| 110 // UINavigationController causes the view to render as a blank/black | |
| 111 // page when a http redirection occurs. | |
| 112 return [[UINavigationController alloc] | |
| 113 initWithRootViewController:[[GTMOAuth2ViewControllerTouch alloc] | |
| 114 initWithScope:Scopes() | |
| 115 clientID:ClientId() | |
| 116 clientSecret:ClientSecret() | |
| 117 keychainItemName:kKeychainItemName | |
| 118 delegate:delegate | |
| 119 finishedSelector:finishedSelector]]; | |
| 120 } | |
| 121 | |
| 122 @end | |
| OLD | NEW |