How to redirect from Yahoo to my IOS app after authentication?
Asked Answered
A

2

8

I am working on an app where I have to use Yahoo account to login. I had gone through this link and followed the procedure as it was there.But I am unable to get back to my app after authentication.After googling I found an answer here.Here he said that "Add an URL Scheme in your info.plist file with the YOUR_APP_ID_OR_BUNDLE_ID" I did the same,but unable to redirect from yahoo to my app.If any one worked on this please help me.Thanks in advance.

This is what I had done in my URL Schemesenter image description here

where JCzOzd44 is my app ID.

In yahoo account while creating the app.what should I give in "Application Domain"

enter image description here

Agitprop answered 30/9, 2013 at 9:25 Comment(0)
A
5

I have found the solution though with a little overheads. Steps are: 1> Create a PHP script in you own server (say named, YRedirect.php). 2> Paste the following code in it-

CODE
<?php
$query = $_SERVER['QUERY_STRING'];
header("Location: com-mycompany-myapp://oauth-response?" . $query);
>

Where "com-mycompany-myapp" is your bundle identifier

3> Add an URL Scheme in your info.plist file with the YOUR_APP_ID_OR_BUNDLE_ID. That's it and you are DONE with the authentication problem.

In your code

[self.session sendUserToAuthorizationWithCallbackUrl:@"http://yourdomain.com/YRedirect.php"];

Then, register a custom URL scheme for your iPhone application from your Info.plist file, and then setup your server side script to redirect Safari back to your application via the URL scheme you just set up.

Thanks for this valuable information. Following your instructions I got the auth & call back working and the php page loads the app.

Agitprop answered 2/10, 2013 at 10:52 Comment(0)
L
5

I didn't work with the Yahoo! API yet, but in oauth it works like that:

  • Create an url scheme in your app. You can do that in the Info section of your project settings (URL types). Name the scheme whatever you want, for example your app id.

  • When you authenticate your app, you can pass a parameter named oauth_callback. Here you have to pass the name of the just created url scheme.

This should be it - when the login is ok on the Yahoo side, it will try to open the app that is registered for the url scheme it got as callback parameter.

UPDATE:

From the Yahoo! API documentation - this is the call you do when requesting the oauth token somewhere in your code (I filled in your url scheme as the callback, this is how it should look like):

https://api.login.yahoo.com/oauth/v2/  
  get_request_token?oauth_nonce=ce2130523f788f313f76314ed3965ea6  
  &oauth_timestamp=1202956957  
  &oauth_consumer_key=123456891011121314151617181920  
  &oauth_signature_method=plaintext  
  &oauth_signature=abcdef  
  &oauth_version=1.0  
  &xoauth_lang_pref="en-us"  
  &oauth_callback="JCzOzd44://"

Of course the request should be signed.

Lloyd answered 30/9, 2013 at 10:29 Comment(3)
Thanks for your reply @TheEye.I had done what u told.Could you see my edited question with image.Agitprop
And what is the URL you use to authenticate with the Yahoo API? The one with the callback?Lloyd
I got stuck there itself.What should be the call back URL? Please dont mind to give reply if u feel it as silly quesion @ TheEyeAgitprop
A
5

I have found the solution though with a little overheads. Steps are: 1> Create a PHP script in you own server (say named, YRedirect.php). 2> Paste the following code in it-

CODE
<?php
$query = $_SERVER['QUERY_STRING'];
header("Location: com-mycompany-myapp://oauth-response?" . $query);
>

Where "com-mycompany-myapp" is your bundle identifier

3> Add an URL Scheme in your info.plist file with the YOUR_APP_ID_OR_BUNDLE_ID. That's it and you are DONE with the authentication problem.

In your code

[self.session sendUserToAuthorizationWithCallbackUrl:@"http://yourdomain.com/YRedirect.php"];

Then, register a custom URL scheme for your iPhone application from your Info.plist file, and then setup your server side script to redirect Safari back to your application via the URL scheme you just set up.

Thanks for this valuable information. Following your instructions I got the auth & call back working and the php page loads the app.

Agitprop answered 2/10, 2013 at 10:52 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.