tamilstreetboy / socialauth-net

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

"Invalid Request Token received" error is comming when we tried it for google. #68

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
Hi All,

I am using the Socialauth for google, but its givign an error after login 
screen i.e. "Invalid Request Token received".

I am also attaching the full exception here.

Invalid Request Token received.
Provider returned: 
openid.ns=http://specs.openid.net/auth/2.0&openid.mode=id_res&openid.op_endpoint
=https://www.google.com/accounts/o8/ud&openid.response_nonce=2012-03-30T12:05:53
Zp0AOMIamlZTxHQ&openid.return_to=http://vmwctosp07-lab.hqdev.netapp.com/MultiAut
hSTS/multiauth/validate.mauth&openid.assoc_handle=AMlYA9UZU1hW4btWHgP-R3KXwEPDC3
rA8LTHQi8TTlLg8d8errCAvfQB&openid.signed=op_endpoint,claimed_id,identity,return_
to,response_nonce,assoc_handle,ns.ext1,ext1.mode,ext1.type.firstname,ext1.value.
firstname,ext1.type.email,ext1.value.email,ext1.type.language,ext1.value.languag
e,ext1.type.lastname,ext1.value.lastname,ext1.type.country,ext1.value.country&op
enid.sig=D7Vi8eRNOmXTQcDVFCA9YRLlQIE&openid.identity=https://www.google.com/acco
unts/o8/id?id&openid.claimed_id=https://www.google.com/accounts/o8/id?id&openid.
ns.ext1=http://openid.net/srv/ax/1.0&openid.ext1.mode=fetch_response&openid.ext1
.type.firstname=http://axschema.org/namePerson/first&openid.ext1.value.firstname
=Manish+Prabhakar&openid.ext1.type.email=http://axschema.org/contact/email&openi
d.ext1.value.email=manish.p.misra@gmail.com&openid.ext1.type.language=http://axs
chema.org/pref/language&openid.ext1.value.language=en-US&openid.ext1.type.lastna
me=http://axschema.org/namePerson/last&openid.ext1.value.lastname=Misra&openid.e
xt1.type.country=http://axschema.org/contact/country/home&openid.ext1.value.coun
try=IN 
Description: An unhandled exception occurred during the execution of the 
current web request. Please review the stack trace for more information about 
the error and where it originated in the code. 

Exception Details: MultiAuth.NET.Core.OAuthException: Invalid Request Token 
received.
Provider returned: 
openid.ns=http://specs.openid.net/auth/2.0&openid.mode=id_res&openid.op_endpoint
=https://www.google.com/accounts/o8/ud&openid.response_nonce=2012-03-30T12:05:53
Zp0AOMIamlZTxHQ&openid.return_to=http://vmwctosp07-lab.hqdev.netapp.com/MultiAut
hSTS/multiauth/validate.mauth&openid.assoc_handle=AMlYA9UZU1hW4btWHgP-R3KXwEPDC3
rA8LTHQi8TTlLg8d8errCAvfQB&openid.signed=op_endpoint,claimed_id,identity,return_
to,response_nonce,assoc_handle,ns.ext1,ext1.mode,ext1.type.firstname,ext1.value.
firstname,ext1.type.email,ext1.value.email,ext1.type.language,ext1.value.languag
e,ext1.type.lastname,ext1.value.lastname,ext1.type.country,ext1.value.country&op
enid.sig=D7Vi8eRNOmXTQcDVFCA9YRLlQIE&openid.identity=https://www.google.com/acco
unts/o8/id?id&openid.claimed_id=https://www.google.com/accounts/o8/id?id&openid.
ns.ext1=http://openid.net/srv/ax/1.0&openid.ext1.mode=fetch_response&openid.ext1
.type.firstname=http://axschema.org/namePerson/first&openid.ext1.value.firstname
=Manish+Prabhakar&openid.ext1.type.email=http://axschema.org/contact/email&openi
d.ext1.value.email=manish.p.misra@gmail.com&openid.ext1.type.language=http://axs
chema.org/pref/language&openid.ext1.value.language=en-US&openid.ext1.type.lastna
me=http://axschema.org/namePerson/last&openid.ext1.value.lastname=Misra&openid.e
xt1.type.country=http://axschema.org/contact/country/home&openid.ext1.value.coun
try=IN

Source Error: 

Line 122:                    throw new 
OAuthException(ErrorMessages.RequestTokenResponseInvalid(responseCollection));
Line 123:                }
Line 124:            QueryParameters openIDValues = new QueryParameters();
Line 125:            if (responseCollection.HasName("openid.ns.ext1"))
Line 126:            {

Please help me, so I can resolve this error.

Thanks in advance.

Original issue reported on code.google.com by manish.p...@gmail.com on 30 Mar 2012 at 12:09

GoogleCodeExporter commented 9 years ago
I have a Google Oauth2 wrapper that solves this problem. If you want it I'll 
send it to you. It's not polished at this point and but it works.

Original comment by j...@crawford.cc on 12 Apr 2012 at 11:24

GoogleCodeExporter commented 9 years ago
Hi Josh,
First of all Thank for your response.

I tried the code and the "Invalid token" error is gone. But now there is new 
error is comming.
i.e.

An error occurred while requesting Access Token at 
https://accounts.google.com/o/oauth2/token?client_id=861085065391.apps.googleuse
rcontent.com&client_secret=dlRzZsBnqzMa9xjvIaTN5jdZ&code=4/p0EqcuXSwUXl6sfSB2ibD
KCfnJa5&redirect_uri=http://localhost/SocialAuthSTS/socialauth/validate.sauth&gr
ant_type=authorization_codeThe remote server returned an error: (405) Method 
Not Allowed.

I tried with default and custom scopes, but its giving the same error. Please 
look into it.
Thanks
Manish

Original comment by manish.p...@gmail.com on 16 Apr 2012 at 6:32

GoogleCodeExporter commented 9 years ago
One more update, If i dont put any scope or just use ScopeLevel="DEFAULT" it 
give the following error:

Error: invalid_request
Missing required parameter: scope

Request Details
response_type=code
scope=
redirect_uri=http://localhost/SocialAuthSTS/socialauth/validate.sauth
client_id=861085065391.apps.googleusercontent.com

Original comment by manish.p...@gmail.com on 16 Apr 2012 at 6:37

GoogleCodeExporter commented 9 years ago
This is the wrapper I'm currently using for Google. It's using their oauth2 
instead of a hybrid system. It's not polished, but it's working. I did not 
include default scopes so you'll have to add them or include them in the web 
config.

/*
===========================================================================
Copyright (c) 2010 BrickRed Technologies Limited

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
===========================================================================

*/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using System.Net;
using System.IO;
using Brickred.SocialAuth.NET.Core.BusinessObjects;
using System.Collections.Specialized;
using System.Xml.Linq;
using log4net;
using Newtonsoft.Json.Linq;

namespace Brickred.SocialAuth.NET.Core.Wrappers
{
    internal class GoogleWrapper : Provider, IProvider
    {
        #region IProvider Members

        //****** PROPERTIES
        private static readonly ILog logger = log4net.LogManager.GetLogger("GoogleWrapper");
        public override PROVIDER_TYPE ProviderType { get { return PROVIDER_TYPE.GOOGLE; } }
        public override string UserLoginEndpoint { get { return "https://accounts.google.com/o/oauth2/auth"; } set { } }
        public override string AccessTokenEndpoint { get { return "https://accounts.google.com/o/oauth2/token"; } }
        public override OAuthStrategyBase AuthenticationStrategy { get { return new OAuth2_0server(this); } }
        public override string ProfileEndpoint { get { return "https://www.googleapis.com/oauth2/v1/userinfo"; } }
        public override string ContactsEndpoint { get { return "https://www.google.com/m8/feeds/contacts/default/full/?max-results=1000&"; } }

        public override SIGNATURE_TYPE SignatureMethod { get { throw new NotImplementedException(); } }
        public override TRANSPORT_METHOD TransportName { get { return TRANSPORT_METHOD.POST; } }

        public override string DefaultScope { get { return ""; } }

        //****** OPERATIONS
        public override UserProfile GetProfile()
        {
            Token token = SocialAuthUser.GetCurrentUser().GetConnection(ProviderType).GetConnectionToken();
            OAuthStrategyBase strategy = AuthenticationStrategy;
            string response = "";

            //If token already has profile for this provider, we can return it to avoid a call
            if (token.Profile.IsSet)
            {
                logger.Debug("Profile successfully returned from session");
                return token.Profile;
            }

            try
            {
                logger.Debug("Executing Profile feed");
                Stream responseStream = strategy.ExecuteFeed(ProfileEndpoint, this, token, TRANSPORT_METHOD.GET).GetResponseStream();
                response = new StreamReader(responseStream).ReadToEnd();
            }
            catch
            {
                throw;
            }

            try
            {

                JObject jsonObject = JObject.Parse(response);
                token.Profile.ID = jsonObject.Get("id");
                token.Profile.FirstName = jsonObject.Get("given_name");
                token.Profile.LastName = jsonObject.Get("family_name");
                token.Profile.Username = jsonObject.Get("name");
                token.Profile.DisplayName = token.Profile.FullName;
                token.Profile.Language = jsonObject.Get("locale");
                token.Profile.ProfileURL = jsonObject.Get("link");
                token.Profile.Email = HttpUtility.UrlDecode(jsonObject.Get("email"));
                //if (!string.IsNullOrEmpty(jsonObject.Get("birthday")))
                //{
                //    string[] dt = jsonObject.Get("birthday").Split(new char[] { '/' });
                //    token.Profile.DateOfBirth = dt[1] + "/" + dt[0] + "/" + dt[2];
                //}
                token.Profile.GenderType = Utility.ParseGender(jsonObject.Get("gender"));
                //get profile picture
                if (!string.IsNullOrEmpty(ProfilePictureEndpoint))
                {
                    token.Profile.ProfilePictureURL = jsonObject.Get("picture");
                }
                token.Profile.IsSet = true;
                logger.Info("Profile successfully received");
                //Session token updated with profile
            }
            catch (Exception ex)
            {
                logger.Error(ErrorMessages.ProfileParsingError(response), ex);
                throw new DataParsingException(ErrorMessages.ProfileParsingError(response), ex);
            }

            return token.Profile;
        }
        public override List<Contact> GetContacts()
        {
            Token token = SocialAuthUser.GetCurrentUser().GetConnection(this.ProviderType).GetConnectionToken();

            //If only OpenID is used and also there is no scope for contacts, return blank list straight away
            if (string.IsNullOrEmpty(token.AccessToken) || !(GetScope().ToLower().Contains("/m8/feeds")))
                return new List<Contact>();

            IEnumerable<Contact> contacts;
            string response = "";
            try
            {
                logger.Debug("Executing contacts feed");
                Stream responseStream = AuthenticationStrategy.ExecuteFeed(ContactsEndpoint, this, token, TRANSPORT_METHOD.GET).GetResponseStream();
                response = new StreamReader(responseStream).ReadToEnd();
            }
            catch { throw; }
            try
            {
                XDocument contactsXML = XDocument.Parse(response);
                XNamespace xn = "http://schemas.google.com/g/2005";
                contacts = from c in contactsXML.Descendants(contactsXML.Root.GetDefaultNamespace() + "entry")
                           select new Contact()
                           {
                               ID = c.Element(contactsXML.Root.GetDefaultNamespace() + "id").Value,
                               Name = c.Element(contactsXML.Root.GetDefaultNamespace() + "title").Value,
                               Email = (c.Element(xn + "email") == null) ? "" : c.Element(xn + "email").Attribute("address").Value,
                               ProfilePictureURL = ""
                           };
                logger.Info("Contacts successfully received");
            }
            catch (Exception ex)
            {
                logger.Error(ErrorMessages.ContactsParsingError(response), ex);
                throw new DataParsingException(ErrorMessages.ContactsParsingError(response), ex);
            }
            return contacts.ToList();

        }
        public override WebResponse ExecuteFeed(string feedUrl, TRANSPORT_METHOD transportMethod)
        {
            logger.Debug("Calling execution of " + feedUrl);
            return AuthenticationStrategy.ExecuteFeed(feedUrl, this, SocialAuthUser.GetCurrentUser().GetConnection(ProviderType).GetConnectionToken(), transportMethod);
        }
        public static WebResponse ExecuteFeed(string feedUrl, string accessToken, string tokenSecret, TRANSPORT_METHOD transportMethod)
        {
            var wrapper = new GoogleWrapper();
            return wrapper.AuthenticationStrategy.ExecuteFeed(feedUrl, wrapper, new Token() { AccessToken = accessToken, TokenSecret = tokenSecret }, transportMethod);
        }

        #endregion
    }
}

Original comment by j...@crawford.cc on 17 Apr 2012 at 10:18

GoogleCodeExporter commented 9 years ago
Yes, I have met this issue.
And I debugged into the source and 
found that if the AdditionalScopes is not null or ScopeLevel is default, the 
token must be put into the response's url, but google does not do it.
So I changed the webConfig file 
(AdditionalScopes="" ScopeLevel="CUSTOM") 

Then it works well now.
You can try it.
If you have any other questions, feel free to contact me by email.
thanks

Original comment by huqiang...@gmail.com on 4 May 2012 at 4:35

GoogleCodeExporter commented 9 years ago
Thanks a lot Hu. We will put this in the documentation as well.

Original comment by tsg.bric...@gmail.com on 4 May 2012 at 2:54

GoogleCodeExporter commented 9 years ago
I Got Error For LinkDin 
--->
An error occurred while requesting Request Token at 
https://api.linkedin.com/uas/oauth/requestToken
with parameters 
oauth_consumer_key=fk2gdvj0r7ta&oauth_signature_method=HMACSHA1&oauth_timestamp=
1343389505&oauth_nonce=1415092&oauth_version=1.0&oauth_callback=http://socialnet
.somee.com/SocialAuth/validate.sauth&oauth_signature=Zs8KBLehfoxS752ME58jWShtrz8
=
Please ensure all required parameters are passed, Signature is Url Encoded and 
Authorization header is properly set!

Original comment by samir.s...@indianic.com on 27 Jul 2012 at 11:26

GoogleCodeExporter commented 9 years ago
Getting Error for Yahoo also,
->>>
An error occurred while requesting Access Token at 
https://api.login.yahoo.com/oauth/v2/get_token?oauth_consumer_key=dj0yJmk9b3dJdE
oxSk1RQXJ4JmQ9WVdrOWJ6Qk1jREpoTjJrbWNHbzlNVEEyT0RneU1qTTJNZy0tJnM9Y29uc3VtZXJzZW
NyZXQmeD1jOA--&oauth_token=BcqsTktu3AbkTWCKVzLF7IoXSv6N02TwLkPDfK0Do5HdlEPmCyMpB
DXZ285ludH99flkAkgmhI9t3GwV7JxkoA2aE_SRDh2StCIOYhKvMIlshZ1gG9z2RkpkY6Sl27hU6pB6Q
vghlNCkPf5NbrN2SBP9UM0c8uR6IYrVV8eTCK1QRkEbmsP4kFdErnXXNvGd.xnG2nyDJP_6yBAWLl5lp
8EfdfIy_E3fSADTJBmbb.2.&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1343389
626&oauth_nonce=8674433&oauth_version=1.0&oauth_signature=bvQ9CJDVpL+PiqG7SQn6E2
HYnyg=
with parameters 
oauth_consumer_key=dj0yJmk9b3dJdEoxSk1RQXJ4JmQ9WVdrOWJ6Qk1jREpoTjJrbWNHbzlNVEEyT
0RneU1qTTJNZy0tJnM9Y29uc3VtZXJzZWNyZXQmeD1jOA--&oauth_token=BcqsTktu3AbkTWCKVzLF
7IoXSv6N02TwLkPDfK0Do5HdlEPmCyMpBDXZ285ludH99flkAkgmhI9t3GwV7JxkoA2aE_SRDh2StCIO
YhKvMIlshZ1gG9z2RkpkY6Sl27hU6pB6QvghlNCkPf5NbrN2SBP9UM0c8uR6IYrVV8eTCK1QRkEbmsP4
kFdErnXXNvGd.xnG2nyDJP_6yBAWLl5lp8EfdfIy_E3fSADTJBmbb.2.&oauth_signature_method=
HMACSHA1&oauth_timestamp=1343389626&oauth_nonce=8674433&oauth_version=1.0&oauth_
signature=bvQ9CJDVpL%2BPiqG7SQn6E2HYnyg%3D
Unauthorized! Please ensure:
(1) All required parameters are passed
(2) Signature is Url Encoded
(3) Authorization header is properly set

-> 

I tried with default and custom scopes, but its giving the same error. Please 
look into it.

Thanks.
Samir

Original comment by samir.s...@indianic.com on 27 Jul 2012 at 11:28

GoogleCodeExporter commented 9 years ago
We'll analyze and revert.
But I remember Yahoo was working earlier for you. Did application stopped 
working all of a sudden or has there been any environment/code change? This 
information would help in better diagnosing root cause.
Deepak

Original comment by daggar...@brickred.com on 27 Jul 2012 at 11:44

GoogleCodeExporter commented 9 years ago
Sorry for late reply,

but i didn't change any thing in environment and in code, though it is giving 
me error in yahoo, linkedin and not getting google contact...

thanks for reply
samir.

Original comment by samir.s...@indianic.com on 30 Jul 2012 at 6:30

GoogleCodeExporter commented 9 years ago
Hi Samir,

Is it possible for you to share key/secret you are using for problem account 
(Don't put it here. Instead send it to tsg@brickred.com). However, if for 
secutiry concerns you're uncomfortable doing so (which is totally fine and 
understood), please perform one activity. Download our demo application (which 
is there in 2.3 package), apply your keys/secrets and revert if demo 
application worked well with them? If it doesn't we can narrow down problem.

Thanks.

Original comment by daggar...@brickred.com on 30 Jul 2012 at 6:42

GoogleCodeExporter commented 9 years ago
From https://developers.google.com/accounts/docs/OAuth2WebServer, the token is 
through POST method. The method "public void RequestForAccessToken()" in 
OAuth2_0Server.cs is using HTTP GET. That's why there would be 405 error.

Original comment by soros....@gmail.com on 13 Sep 2012 at 4:09

GoogleCodeExporter commented 9 years ago
Hi,
Is your problem resolved? Did you try demo application?
Deepak

Original comment by deepak.a...@3pillarglobal.com on 30 Oct 2012 at 8:35

GoogleCodeExporter commented 9 years ago
As regarding POST content from Google, this is noted but it needs a change in 
library. If you need it urgently, please check CallbackHandler.cs file in Core 
project which reads the URL and makes the properties. We've noted this and 
would make necessary changes in next release.

Since the original issue was resolved I'm closing this one and request others 
to add new issues for prompt reply. I'll be adding a ticket just next to handle 
information coming from POST response.

Deepak

Original comment by deepak.a...@3pillarglobal.com on 17 Dec 2012 at 6:45

GoogleCodeExporter commented 9 years ago
Any further information on the 405 error?

I need to import GMail contacts, so AdditionalScopes is set to 
"https://www.google.com/m8/feeds/" and ScopeLevel="CUSTOM"

-Even using Josh's Google Wrapper, I get the 405 error.
-Setting the request.Method to "GET" on public void RequestForAccessToken() 
changes nothing.
-Setting AdditionalScopes to "" triggers the "Missing required parameter: 
scope" error
-The demo application does not work (Invalid token received) when using the 
"https://www.google.com/m8/feeds/" scope

Any ideas?

Thanks in advance!

Original comment by jonayre...@gmail.com on 21 Mar 2013 at 1:55