문제

I am trying to build a web site which uses survey monkey API methods to show data, for that I am building a class library in which I will call one(only one from some controller) method which should do the oauth of the user.(I was successful with the 3 step process mentioned in the survey monkey website) but now I want to call only one method from the controller to a method in class library which will do the oauth of the user and sets the token which can later be used for API methods. My code is like this in the class library:

HttpContext.Current.Response.Redirect(urlToAuthorize);

//what should be here (I should wait till the user gives credentials and authorize so that I can get the query string)

string tempAuthCode = HttpContext.Current.Session["code"].ToString();
if (!verifyRedirectedTempCode(tempAuthCode))
{
    return "Not a valid Token";
}
else
{
    try
    {
        var webRequest = GetWebRequestForHttpPostOfSurveyMonkeyToken(ApiKey,ClientSecret,tempAuthCode,RedirectUri,ClientId,GrantType,ContentType,WebRequestMethod);
        using (HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse())
        {
            string tokenJson = new StreamReader(response.GetResponseStream()).ReadToEnd();
            AccessToken accesstokenObj = JsonConvert.DeserializeObject<AccessToken>(tokenJson);
            return accesstokenObj.Token.ToString();
        }
    }
    catch
    {
        return null;
    }
}

}

After redirecting its not waiting for the user to authorize.So,its not working exactly as I am thinking. How to wait till the User authorize and collect this query string? It should be done in class library itself.

도움이 되었습니까?

해결책

You can't handle it like this. OAuth is a two-stage process. You redirect to the OAuth provider and then once the user authorizes there, they redirect back to your site, where you pickup where you left off.

That means you need two actions for this: one to initiate the process and one to receive the payload from the provider after authorization.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top