Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OSX OAuth redirect_uri in WebView

I'm trying to authenticate an OSX app via OAuth - specifically, using the Instagram API . I've setup an app with Instagram - have the client ID and secret - but I'm unsure of how to deal with the redirect_url and how to retrieve the access_token, once authenticated.

So far I've just a simple WebView which loads the login page...

[[_webView mainFrame] loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://instagram.com/oauth/authorize/?client_id=THECLIENTID&redirect_uri=REDIRECT_URI&response_type=code"]]];
like image 720
daihovey Avatar asked Feb 21 '13 06:02

daihovey


1 Answers

Implement the method - (void)webView:(WebView *)webView didFinishLoadForFrame:(WebFrame *)webFrame from the WebFrameLoadDelegate informal delegate. Then (in Interface Builder) wire up the outlet frameLoadDelegate from the WebView to an instance of the class where you implemented - (void)webView:(WebView *)webView didFinishLoadForFrame:(WebFrame *)webFrame. Example implementation:

- (void)webView:(WebView *)webView didFinishLoadForFrame:(WebFrame *)webFrame {
    NSString *currentURL = [[[[webFrame dataSource] request] URL] absoluteString];
    NSLog(@"Our WebView just loaded: %@", currentURL);
    if ([currentURL hasPrefix:yourRedirectURIString]) {
        // We are at the redirect URI!
    }
}
like image 52
11684 Avatar answered Nov 15 '22 05:11

11684