2
Answers

Problem With Yahoo Login with open authentication

Deepak Pandey

Deepak Pandey

13y
2.2k
1
Hello,

I am using this code to for request token to use Sign in With yahoo using Oenid
this code is showing errorerror "oauth_problem=consumer_key_rejected"

what is wrong with code and what will be the correct code
Collapse | Copy Code

private void MakeRequestForToken()
{
string consumerKey =ConfigurationManager.AppSettings["YahooConsumerKey"];
string consumerSecret =ConfigurationManager.AppSettings["YahooConsumerSecret"];

string requestTokenEndpoint = "https://api.login.yahoo.com/oauth/v2/get_request_token";
string requestTokenCallback = GetRouteableUrlFromRelativeUrl("YahooValidation.aspx/authorizeToken/yahoo/");
string authorizeTokenUrl = "https://api.login.yahoo.com/oauth/v2/request_auth";

// Step 1: Make the call to request a token
var oAuthConsumer = new OAuthConsumerNew();
var requestToken = oAuthConsumer.GetOAuthRequestToken(requestTokenEndpoint, realm, consumerKey, consumerSecret, requestTokenCallback);
PersistRequestToken(requestToken);


// Step 2: Make a the call to authorize the request token
Response.Redirect(authorizeTokenUrl + "?oauth_token=" + requestToken.Token);
}



Collapse | Copy Code

private void HandleAuthorizeTokenResponse()
{
string consumerKey =ConfigurationManager.AppSettings["YahooConsumerKey"];
//string consumerSecret =ConfigurationManager.AppSettings["YahooConsumerSecret"];

string token = Request.QueryString["oauth_token"];
string verifier = Request.QueryString["oauth_verifier"];
string accessTokenEndpoint = "https://api.login.yahoo.com/oauth/v2/request_auth";

// Exchange the Request Token for an Access Token
var oAuthConsumer = new OAuthConsumerNew();

var accessToken = oAuthConsumer.GetOAuthAccessToken(accessTokenEndpoint, realm, consumerKey, consumerSecret, token, verifier, GetRequesttoken().TokenSecret);


var responseText = oAuthConsumer.GetUserInfo("https://www.yahoo.com/userinfo/email", realm, consumerKey, consumerSecret, accessToken.Token, accessToken.TokenSecret);

string queryString = responseText;
NameValueCollection nvc = StringToNameValueCollection(responseText);

if (nvc["email"] != "")
{
string userName = "";
//string password = "";
userName = nvc["email"].ToString();
}
}



and what will be the string accessTokenEndpoint = "https://api.login.yahoo.com/oauth/v2/request_auth";

Is this accessTokenEndpoint retrive user information like userid,firstname and lastname
or if this will not return this value then what should use to get resired result form yahoo login

Thanks,
Deepak

Answers (2)