0

Im converting to MVC from webforms. My app uses oAuth (DevDefinedOauth).

Here is some code used in the webforms application AND the MVC app (I have commented the webforms response.redirect). This code runs in a protected void method within the controller (MVC) or within the .CS file (webforms)

var session = new OAuthSession(consumerContext, requestUrl, userAuthorizeUrl, accessUrl, callBackUrl);

        // get a request token from the provider 
        IToken requestToken = session.GetRequestToken();

        // generate a user authorize url for this token (which you can use in a redirect from the current site) 
        string authorizationLink = session.GetUserAuthorizationUrlForToken(requestToken, callBackUrl);

        Session["oAuthSession"] = session;
        Session["oAuthToken"] = requestToken;

        //Old Response Redirect from Webforms
        //Response.Redirect(authorizationLink);

        Redirect(authorizationLink);

In MVC, using the regular webforms response.redirect (commented), it seems to work, it takes me to the expcted Authorization page (yahoo) however it is not quite right because once i accept the oauth, the page crashes when it returns to my own page.

NOTE - If i FIRST use my old aspx page to authenticate, then go over to my controller/action that is using oauth, everything works properly. (Probably because the session is storing/working p0roperly?)

I'm new to oauth. I am just happy it is working, even if i have to use the aspx site first. Is there a proper way to do this using MVC though?

dave317
  • 754
  • 2
  • 12
  • 30

1 Answers1

0

If you are looking for implementing OAuth in MVC and Web API, Please refer the below stackoverflow link to implement OAuth in the existing code

How to implement oauth2 server in ASP.NET MVC 5 and WEB API 2

arun thatham
  • 500
  • 1
  • 4
  • 13
  • I feel that link explains how to secure your own server using Oauth? I am trying to make calls to Yahoo's API using Oauth. As mentioned, it works in webforms, I am encountering difficulty using MVC – dave317 Jun 15 '17 at 13:59