Having trouble connecting to google oauth.

17 views
Skip to first unread message

Ben

unread,
Apr 15, 2009, 5:14:07 AM4/15/09
to OAuth Objective-C
I've managed to use the MPOAuthMobile example to connect to Twitter
but am having trouble connecting to Google.

_oauthAPI = [[MPOAuthAPI alloc]
initWithCredentials:credentials
authenticationURL:[NSURL URLWithString:@"https://www.google.com/
accounts/OAuthAuthorizeToken"]
andBaseURL:[NSURL URLWithString:@"https://www.google.com/"]];

I've registered my domain/application with them and have my consumer
key and secret.

When I run the app, I get an "Invalid Token" message when redirected
to for login details.

I did notice however that a variable called "scope" is Required when
requesting the request token. See:
http://code.google.com/apis/accounts/docs/OAuth.html#RequestToken

and am wondering if this has something to do with causing the problem.

I can't see a way to pass in extra-parameters through the URL or
Body.

Is there something I'm not understanding or missing?

Thanks.

Karl Adam

unread,
Apr 15, 2009, 5:20:27 AM4/15/09
to oauth-ob...@googlegroups.com
You're correct that a scope is required to get a valid Request Token
and continue on to user requests. In order to set that request token
you'd need to manually set that as your -oauthRequestTokenURL and
include your scope parameter in that URL. MPOAuth will deconstruct
that URL and parameter and correctly sign the URL as necessary adding
the remaining oauth specific URL parameters.

_Karl
Message has been deleted
Message has been deleted

Karl Adam

unread,
Apr 15, 2009, 12:35:25 PM4/15/09
to oauth-ob...@googlegroups.com
Well, for starters your scope URL isn't URL encoded and somewhere your parameter is being discarded before the url is requested. I'm not sure if the two are related, but I'll take a look more closely in a little bit to find out where this is happening specifically.

_Karl

On Apr 15, 2009, at 04:12:50, Ben Priebe wrote:

Thanks for the quick reply.

So I've changed the oauthAutoConfig.plist -> .google -> MPOAuthRequestTokenURL to be:


the MPLog in the MPOAuthAPI.m->_authenticationRequestForAccessToken method writes:



and the [self.userAuthURL description] in the UserAuthViewController shows
It appears as if the ?scope= parameter is not doing the job.
I tried changing it to be &scope= but that doesn't work either.

Sorry for being such a n00b. What should I be trying?

Dil

unread,
Jun 1, 2009, 8:20:29 AM6/1/09
to OAuth Objective-C
Sorry to ask such a kind of question. First where to download that
MPOAuthMobile API in google each file is separated i want to it as a
complete project!!! PLz help me!!

dshanley

unread,
Jun 1, 2009, 6:23:00 PM6/1/09
to OAuth Objective-C
Would it make sense to move:

[self authenticate];

out of the - initWithCredentials:authenticationURL:andBaseURL:
method? This way there would be a separation between initialization
and execution.

I don't see a clear way of setting oauthRequestTokenURL, otherwise,
without re-implementing initWithCredentials, because authenticate gets
called.

Is the intent here that we should subclass MPOAuthAPI for situations
like this?

Thanks - great addition to the community!

Karl Adam

unread,
Jun 1, 2009, 6:31:02 PM6/1/09
to oauth-ob...@googlegroups.com
Authentication doesn't do anything if the oauth*URLs aren't set. If
there are no appropriate authorization endpoints for your URL then
nothing happens and you'd set them and then manually call
authenticate. I should probably clear up the docs to make that more
obvious. I've been busy doing some reworking for OAuth Rev A, OAuth
Auto-Discovery, so that the oauthConfiguration endpoints plist is no
longer necessary or can serve as a fallback rather than primary
configuration.

You can set all the oauth dance endpoints directly as they're
properties on the MPOAuthAPI object. For situations as you describe
it's best to just initialize your object then set the properties for
your oauth*URLs.

_Karl

dshanley

unread,
Jun 1, 2009, 7:34:11 PM6/1/09
to OAuth Objective-C
Ok - that makes sense.

Regarding the scope parameter that google requires - I'm also seeing
it dropped from the request. I added it to the oauthRequestTokenURL
as an escaped string.
The URL looks malformed when the credential parameters are added in
MPOAuthURLRequest urlRequestSignedWithSecret:usingMethod, because it
doesn't look for the existence of a query string - just the size of
the parameters array. Passing parameters on the request URL never get
stripped off and put into this array. This is probably why the
previous poster was having trouble too.

I tried a quick work around in that method:

...
if ([[self HTTPMethod] isEqualToString:@"GET"] && [self.parameters
count]) {
NSString *urlString;
if([self.url query]){
urlString = [NSString stringWithFormat:@"%@&%@", [self.url
absoluteString], parameterString];
} else {
urlString = [NSString stringWithFormat:@"%@?%@", [self.url
absoluteString], parameterString];
}
...

but I'm still missing something and get the "invalid token" error.
The output in the console is:

2009-06-01 16:25:49.369 MPOAuthMobile[5317:20b]
urlString -
https://www.google.com/accounts/OAuthGetRequestToken?scope=http://www.google.com/calendar/feeds&oauth_consumer_key=www.nixwire.com&oauth_nonce=48B8B6FD-B679-4C50-8D22-C507A0782904&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1243898749&oauth_version=1.0&oauth_signature=mfgZGmWsEQoP449w3%2BFk4eaZzK8%3D

2009-06-01 16:25:49.415 MPOAuthMobile[5317:20b]
[MPOAuthAPIRequestLoader
connection:willSendRequest:redirectResponse:]: <NSURLRequest
https://www.google.com/accounts/OAuthGetRequestToken?scope=http://www.google.com/calendar/feeds&oauth_consumer_key=www.nixwire.com&oauth_nonce=48B8B6FD-B679-4C50-8D22-C507A0782904&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1243898749&oauth_version=1.0&oauth_signature=mfgZGmWsEQoP449w3%2BFk4eaZzK8%3D>,
(null)

Karl Adam

unread,
Jun 1, 2009, 8:09:35 PM6/1/09
to oauth-ob...@googlegroups.com
The problems are two fold. You're correct that the code isn't
expecting a parameter already be attached to the url. The other is
that the scope parameter you've explicitly set isn't URL encoded so
it's a malformed URL with which I've no idea what the NSURL apis did
with it.

So for starters I need to fix the first bug since there may be other
apis with default parameters, and the second bug is one you can fix
locally by putting that in Safari and getting the URL escaped version
of that scope parameter.

As an aside, I assume that wasn't your consumer key but was put in the
url you pasted for demonstration purposes.

_Karl
Reply all
Reply to author
Forward
0 new messages