1

I'm trying to see if I can re-use the facebook access token I'm getting in my iOS app (from the facebook SDK) and pass it to a custom webview (to be logged in to the same app but on the web).

What I have so far: The app currently authenticated correctly on the mobile device (my App switches to FB App and returns to my App with Token)

var accessToken = FBSDKAccessToken.currentAccessToken()
var tokenString = accessToken.tokenString

Any help is appreciated, I spent a lot of time looking for a solution but all the clues I found were outdated and deprecated.

Thank you in advance!

1 Answer 1

0

I am assuming that your question is simply how to pass data from native app to a webview. You can use js. e.g. Suppose this is the code on your webview which uses the access token saved as test.html:

    <html>
      <head></head>
      <body>
          <script type="text/javascript">
            function usesAccessToken(access_token_string) {
             // use access token 
              alert(access_token_string);
            }
            </script>
      </body>
    </html>

You can pass values to the js function in the following manner:

[self.myAppWebView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"]isDirectory:NO]]];

In the UIWebViewDelegate delegate method:

- (void)webViewDidFinishLoad:(UIWebView *)webView {
    NSString *accessToken = [FBSDKAccessToken currentAccessToken].tokenString;
    NSString *functionToCall = [NSString stringWithFormat:@"usesAccessToken('%@')", accessToken];
    [self.myAppWebView stringByEvaluatingJavaScriptFromString:functionToCall];
}
1
  • It might be important to note that sharing access tokens in clients is not advisable.
    – bangdel
    May 14, 2015 at 11:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.