我正在创建一个与Yahoo!交互的WebApi服务使用OAuth 1.0的API。我可以使用MVC来调用并获取访问令牌而没有任何问题。我正在尝试完成这个过程而根本不使用MVC。这就是我想要发生的事情。
以下是目前适用于MVC的代码。
public ActionResult AuthenticateWithYahoo()
{
var callbackUri = new Uri ("http://localhost/yahoo/api/auth/Home/YahooOAuthCallback");
try
{
//this call eventually does this
//var request = this.Consumer.PrepareRequestUserAuthorization(callback, null, null);
//this.Consumer.Channel.Respond(request);
this.Fantasizer.BeginAuthorization(callbackUri);
}
catch (ProtocolException pe)
{
var webException = pe.InnerException as WebException;
if (webException != null)
{
HttpWebResponse response = webException.Response as HttpWebResponse;
if (response != null && response.StatusCode == HttpStatusCode.Unauthorized)
{
var appException =
new ApplicationException(
"Unable to authorize with Yahoo. Check YahooConsumerKey and YahooConsumerSecret environment variables.",
pe);
throw appException;
}
}
throw;
}
// This will not get hit
return null;
}
public ActionResult YahooOAuthCallback()
{
// this ends up calling OAUTH complete authorization
this.Fantasizer.CompleteAuthorization();
return RedirectToAction("ListLeagues", "User");
}
我需要做什么才能将此流程转移到不依赖于MVC的流程?如果可能,在呼叫中传回访问令牌将是理想的。如果需要更多信息,请与我们联系。