lacostabr / socialauth-net

Automatically exported from code.google.com/p/socialauth-net
0 stars 0 forks source link

Exception raised when upgraded to MVC 4.0 #176

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problems?
1.Use SocialAuth in an MVC 3.0 app, 
2.use facebook oauth with additional scope
3.upgrade to MVC4.0
4.no changes to social auth

What is the expected output? What do you see instead?
1) it should run fine as before

What version of the product are you using? On what operating system?
using social-auth 2.1

Please provide any additional information below.

Original issue reported on code.google.com by vishal.a...@gmail.com on 11 Jun 2013 at 7:31

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
still trying to figure what might be wrong

Original comment by vishal.s...@7technologies.net on 12 Jun 2013 at 12:41

GoogleCodeExporter commented 9 years ago
We did try a simple POC with MVC 4.0 sometime back which was working fine. I'd 
recommend you to re-try with latest version (2.3.1)

Original comment by deepak.a...@3pillarglobal.com on 12 Jun 2013 at 9:16

GoogleCodeExporter commented 9 years ago
I think i found it, issue is not really with MVC 4.0, but its behaving absurd, 
i have only updated social auth library to latest tip version and realized that 
ProviderCallback url is now hardcoded in the library and the attribute is not 
supported, also although no changes to my facebook app settings but i started 
receiving 400 Bad request error after facebook passes control back to my web app

Detailed error is: Remote server returned an error, Bad request 400
and the method where i get this error is RequestForAccessToken()

Original comment by vishal.a...@gmail.com on 13 Jun 2013 at 2:24

GoogleCodeExporter commented 9 years ago
I have attached a screen shot of the error i get, :( really absurd, but 
unfortunately its happening, kindly take a look

Original comment by vishal.a...@gmail.com on 13 Jun 2013 at 4:46

Attachments:

GoogleCodeExporter commented 9 years ago
Hi Vishal,

I think I know what is it. I believe it is "//" appearing before socialauth in 
redirect_uri. If you've the sourcecode, could you explicitly replace // with / 
before user is redirected to Fb for login and also when access token is 
requested? Also ensure Fb redirect Url is exact as in your redirect Uri. I'd be 
resolving the 1) in upcoming patch however you'd need to wait for a month or so 
for that.

Deepak

Original comment by deepak.a...@3pillarglobal.com on 13 Jun 2013 at 4:55

GoogleCodeExporter commented 9 years ago
Thanks Deepak, I will try it out and let you know how it goes.. i appreciate 
your prompt response.

Original comment by vishal.a...@gmail.com on 13 Jun 2013 at 5:19

GoogleCodeExporter commented 9 years ago
I tried with single / but it still is same error,

Quick question, is the support for ProviderCallbackUrl pulled off? as the tip 
version gives error

<Authentication Enabled="False" LoginUrl="" DefaultUrl="/" 
ProviderCallBackUrl="mypage.aspx"/>

Original comment by vishal.a...@gmail.com on 13 Jun 2013 at 5:29

GoogleCodeExporter commented 9 years ago
is it possible for you to attempt and reproduce this error at your end, with my 
web config settings

Original comment by vishal.a...@gmail.com on 13 Jun 2013 at 5:56

GoogleCodeExporter commented 9 years ago
Sure. I haven't upgraded to MVC4 yet but I your issue doesn't seem to be tied 
up with that. You can send me your config directly to 
deepak.aggarwal@3pillarglobal.com instead of posting it here. Also, please do 
mention the Url you've used to register your app.

Deepak

Original comment by deepak.a...@3pillarglobal.com on 13 Jun 2013 at 6:03

GoogleCodeExporter commented 9 years ago
Sure Deepak, I am sending it across, 
I am using a app on my fb account (its a testing version of my prod app), the 
settings are as follows on the fb app, let me know if you want me to change 
anything on it..
app domain = localhost
website with facebook login = http://localhost:28924/Member/New

Member/New is the Controller/Action in my mvc app

Original comment by vishal.a...@gmail.com on 13 Jun 2013 at 6:15

GoogleCodeExporter commented 9 years ago
I believe the issue is caused by Facebook breaking changes 
App access tokens will be required for accessing the link_stat FQL table. App 
access tokens will also be required for retrieving data from Graph API endpoint 
for link stats, ie: https://graph.facebook.com/?id=http://example.com.

Original comment by vishal.s...@7technologies.net on 13 Jun 2013 at 6:46

GoogleCodeExporter commented 9 years ago
more details that may help you fix the issue
more digging and debugging explains that actually error is following
{
   "error": {
      "message": "Error validating verification code. Please make sure your redirect_uri is identical to the one you used in the OAuth dialog request",
      "type": "OAuthException",
      "code": 100
   }
}

now i checked that redirect_uri and the one on oAuth diaglog might not be same 
as on the GetLoginUrl(ConnectionToken.ProviderCallbackUrl) method, 
ProviderCallback is now hard coded in the library as opposed to the attribute 
allowed in the config earlier.

Original comment by vishal.s...@7technologies.net on 13 Jun 2013 at 9:34

GoogleCodeExporter commented 9 years ago
ok found it.. it is the // caused by GetBaseUrl in Extension.cs

        public static string GetBaseURL(this HttpRequest request)
        {
            var baseUrlInConfig = Utility.GetSocialAuthConfiguration().BaseURL;
            string protocol = string.IsNullOrEmpty(baseUrlInConfig.Protocol) ? request.Url.Scheme : baseUrlInConfig.Protocol;
            int port = string.IsNullOrEmpty(baseUrlInConfig.Port) ? request.Url.Port : int.Parse(baseUrlInConfig.Port);
            string domain = string.IsNullOrEmpty(baseUrlInConfig.Domain) ? request.Url.Host : baseUrlInConfig.Domain;
            string path =  string.IsNullOrEmpty(baseUrlInConfig.Path)? request.ApplicationPath:baseUrlInConfig.Path;

            UriBuilder uri = new UriBuilder(protocol, domain, port, path);
            return port == 0 ? uri.Uri.GetComponents(UriComponents.Scheme |
                               UriComponents.Host |
                               UriComponents.PathAndQuery,
                               UriFormat.UriEscaped) : uri.Uri.AbsoluteUri +"/";
        }

to fix change the method to 
        public static string GetBaseURL(this HttpRequest request)
        {
            var baseUrlInConfig = Utility.GetSocialAuthConfiguration().BaseURL;
            string protocol = string.IsNullOrEmpty(baseUrlInConfig.Protocol) ? request.Url.Scheme : baseUrlInConfig.Protocol;
            int port = string.IsNullOrEmpty(baseUrlInConfig.Port) ? request.Url.Port : int.Parse(baseUrlInConfig.Port);
            string domain = string.IsNullOrEmpty(baseUrlInConfig.Domain) ? request.Url.Host : baseUrlInConfig.Domain;
            string path =  string.IsNullOrEmpty(baseUrlInConfig.Path)? request.ApplicationPath:baseUrlInConfig.Path;

            UriBuilder uri = new UriBuilder(protocol, domain, port, path);
            return port == 0 ? uri.Uri.GetComponents(UriComponents.Scheme |
                               UriComponents.Host |
                               UriComponents.PathAndQuery,
                               UriFormat.UriEscaped) : uri.Uri.AbsoluteUri;// +"/";
        }

now my redirect_uri and the oauthdialog login url are 100% match... and boom 
its working again for me

Original comment by vishal.s...@7technologies.net on 13 Jun 2013 at 9:54

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Great. Looked like it was same issue as I thought (slashes issue). I appreciate 
that you shared the code changes you did. We'd have this change after checking 
for a few more scenarios in next release.

Regards,
Deepak

Original comment by deepak.a...@3pillarglobal.com on 14 Jun 2013 at 6:21

GoogleCodeExporter commented 9 years ago
error with twitter oauth

Original comment by vishal.a...@gmail.com on 15 Jun 2013 at 7:52