I am writing an application where user can login using Google+. I followed GOOGLE Developer console and successfully logged in and obtained the user profile information through Access_Token. and i want to login through web view, but how to make sign out after login?
My Webview method
-(void)addWebView
{
NSString *url = [NSString stringWithFormat:@"http://ift.tt/Kyk9ty",client_id,callbakc,scope,visibleactions];
self.webview = [[UIWebView alloc]init];
self.webview.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
self.webview.delegate = self;
[self.view addSubview:self.webview];
[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
}
- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {
// [indicator startAnimating];
if ([[[request URL] host] isEqualToString:@"localhost"]) {
// Extract oauth_verifier from URL query
NSString* verifier = nil;
NSArray* urlParams = [[[request URL] query] componentsSeparatedByString:@"&"];
for (NSString* param in urlParams) {
NSArray* keyValue = [param componentsSeparatedByString:@"="];
NSString* key = [keyValue objectAtIndex:0];
if ([key isEqualToString:@"code"]) {
verifier = [keyValue objectAtIndex:1];
NSLog(@"verifier %@",verifier);
break;
}
}
if (verifier) {
NSString *data = [NSString stringWithFormat:@"code=%@&client_id=%@&client_secret=%@&redirect_uri=%@&grant_type=authorization_code", verifier,client_id,secret,callbakc];
NSString *url = [NSString stringWithFormat:@"http://ift.tt/IlrJjr"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[data dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
receivedData = [[NSMutableData alloc] init];
} else {
// ERROR!
}
[webView removeFromSuperview];
return NO;
}
return YES;
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire