2013-10-08 2 views
2

Я пытаюсь получить токен авторизации для OnTime OnDemand API, используя asp.net mvc. ниже приведены мои простые методы действий для получения токена.Получение токена авторизации

public ActionResult Index() 
     { 
      string eURL = HttpUtility.UrlEncode("http://localhost:2574/OnTimeClient/AuthorizationCodeCallback"); 
      return Redirect("https://iss.ontimenow.com/auth?response_type=code&client_id=6457eb4e-42c7-4c19-ad25-73fc0d016e5a&redirect_uri=" +eURL+"&scope=read%20write"); 

     } 

     public ActionResult AuthorizationCodeCallback(string code, string error) 
     { 
      return Redirect("https://iss.ontimenow.com/api/oauth2/token?grant_type=authorization_code&code="+code+"&redirect_uri=www.yahoo.com&client_id=6457eb4e-42c7-4c19-ad25-73fc0d016e5a&client_secret=8538c23b-211f-4351-bfe9-f533e81c97bf"); 
     } 

Я получаю {"error": "invalid_grant"}.

ответ

1

Я решил проблему. redirect_uri должно быть одинаковым в обоих методах.

public ActionResult Index() 
     { 
if(Request.QueryString["code"]==null) 
{ 
      string eURL = HttpUtility.UrlEncode("http://localhost:2574/OnTimeClient/AuthorizationCodeCallback"); 
      return Redirect("https://iss.ontimenow.com/auth?response_type=code&client_id=6457eb4e-42c7-4c19-ad25-73fc0d016e&redirect_uri=" +eURL+"&scope=read%20write"); 
} 
else 
{ 
    //process after obtaining the token 
} 

     } 

     public ActionResult AuthorizationCodeCallback(string code, string error) 
     { 
string eURL = HttpUtility.UrlEncode("http://localhost:2574/OnTimeClient/AuthorizationCodeCallback"); 
      return Redirect("https://iss.ontimenow.com/api/oauth2/token?grant_type=authorization_code&code="+code+"&redirect_uri="+eURL+"&client_id=6457eb4e-42c7-4c19-ad25-73fc0d016e&client_secret=8538c23b-211f-4351-bfe9-f533e81c97bf"); 
     } 
Смежные вопросы