yangchongze00 / google-gdata

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

Getting 401 Not Authorized error using secure AuthSub #393

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Redirect to autentication url:
sReturnValue = AuthSubUtil.getRequestUrl(sContinueUrl, 
"http://gdata.youtube.com", true, true);

2. Exchange single use token with session token:
sReturnValue = AuthSubUtil.exchangeForSessionToken(sToken, GetRsaKey());
where GetRsaKey returns:
cert = new X509Certificate2(sApplicationPath + "Certificates/cert.pfx", 
"certpasswd");
return RSACryptoServiceProvider privateKey = cert.PrivateKey as 
RSACryptoServiceProvider;

3. Perform a simple operation like the following with the exchanged token:
YouTubeRequestSettings settings = new YouTubeRequestSettings("OurApps", 
sDeveloperKey, sToken);
                YouTubeRequest f = new YouTubeRequest(settings);
                Feed<Video> feed = f.GetStandardFeed(YouTubeQuery.MostPopular);
                foreach (Video v in feed.Entries)
                {
                    Feed<Comment> list = f.GetComments(v);
                    foreach (Comment c in list.Entries)
                    {
                        Misc.WriteLog(c.Title);
                    }
                }

What is the expected output? What do you see instead?
Point 1 and 2 perform well, but when I try to execute point 3 I always get 401 
Not authorized error.
I've tryed everything but nothing helps.

What version of the product are you using? On what operating system?
Visual Studio 2008 Professional, site hosted on Windows 2003 Server, Youtube 
.net SDK updated to last version.

Please provide any additional information below.
1) the domain is correctly registraed and verified, "Target URL path prefix" is 
correctly set up to url next prefix of the page receiving one time token
2) the certificate is created using OpenSSL with these commands:
openssl req -x509 -nodes -days 365 -newkey rsa:1024 -sha1 -subj 
"/C=IT/ST=IT/L=Bologna/CN=demo.oursite.com" -keyout cert_key.pem -out 
cert_cert.pem
openssl pkcs12 -export -in cert_cert.pem -inkey cert_key.pem -out cert.pfx 
-name "Demo Certificate"
3) the developer key was correctly registered with the corresponding app name, 
specified in YouTubeRequestSettings

Thank you in advance for any advice!
Fabio

Original issue reported on code.google.com by i...@bmoll.com on 22 Jun 2010 at 1:38

GoogleCodeExporter commented 8 years ago
is the latest v1.6? 

Frank

Original comment by fman...@gmail.com on 22 Jun 2010 at 4:19

GoogleCodeExporter commented 8 years ago
Yes, it's updated to 1.6.0.0
Here's the error message:

22/06/2010 20.05.00.304;Source: Google.GData.Client
Message: Execution of request failed: 
http://gdata.youtube.com/feeds/api/standardfeeds/most_popular
InnerException: System.Net.WebException: Errore del server remoto: (401) Non 
autorizzato.
   in System.Net.HttpWebRequest.GetResponse()
   in Google.GData.Client.GDataRequest.Execute()
Method: Execute
StackTrace:    in Google.GData.Client.GDataRequest.Execute()
   in Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter)
   in Google.GData.Client.GDataGAuthRequest.Execute()
   in Google.GData.Client.Service.Query(Uri queryUri, DateTime ifModifiedSince, String etag, Int64& contentLength)
   in Google.GData.Client.Service.Query(Uri queryUri, DateTime ifModifiedSince)
   in Google.GData.Client.Service.Query(FeedQuery feedQuery)
   in Google.GData.Client.Feed`1.get_AtomFeed()
   in Google.GData.Client.Feed`1.<get_Entries>d__0.MoveNext()

Original comment by i...@bmoll.com on 22 Jun 2010 at 6:28

GoogleCodeExporter commented 8 years ago
According to point 4 of "Posting and Reading Profile Data" of this FAQ 
(http://code.google.com/intl/it-IT/apis/health/faq.html) I have to digitally 
sign every request made with the exchanged token, but in the examples and the 
reference help I can't find a way to sign my request.
What am I missing? How can I sign the request used in point 3 of my issue?

Thanks for yout support!
Fabio

Original comment by i...@bmoll.com on 23 Jun 2010 at 10:38

GoogleCodeExporter commented 8 years ago
Any news?

Thanks!
Fabio

Original comment by i...@bmoll.com on 7 Jul 2010 at 1:27

GoogleCodeExporter commented 8 years ago
I was having the same problem today and think I have solved it. It looks like 
you have to sign each request with the RSA key. Try adding the following lines 
just after creating your YouTubeRequest:

YouTubeRequest request = new YouTubeRequest(settings);

request.Service.RequestFactory = new GAuthSubRequestFactory("youtube", Source)
                                     {
                                         PrivateKey = GetRSAKey(),
                                         Token = Token
                                     };

Original comment by kmjacob...@gmail.com on 25 Aug 2010 at 7:01

GoogleCodeExporter commented 8 years ago
Great! It does the trick :-)
Thank you!!

Original comment by i...@bmoll.com on 31 Aug 2010 at 4:41

GoogleCodeExporter commented 8 years ago
Hello,

Does anyone have the problem when uploading video from server?
Thanks for this issue, I fixed authentication bugs, and it does work on my 
local computer, but does not work at server side.

Btw, local computer does not need certificate, when server does.
I use Server 2008R2, IIS 7.

Any suggestions would be appreciated.

Original comment by an.serge...@gmail.com on 1 Feb 2011 at 4:01

GoogleCodeExporter commented 8 years ago
to comment 7,

never mind guys, it was MIME problem. 

Original comment by an.serge...@gmail.com on 8 Feb 2011 at 11:56

GoogleCodeExporter commented 8 years ago

Original comment by ccherub...@google.com on 9 Feb 2011 at 9:21

GoogleCodeExporter commented 8 years ago
for comment no 5:

request.Service.RequestFactory = new GAuthSubRequestFactory("youtube", Source)

What is Source mean ?

Original comment by youssef....@gmail.com on 11 Jul 2014 at 3:51