mjpan / gtm-oauth2

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

GTMOAuth2Authentication expiresIn can return wrong type #17

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Using Paypal endpoint (sandbox was tested)
2. Login with sandbox credentials
3. method updateExpirationDate throws exception on 
   unsigned long deltaSeconds = [expiresIn unsignedLongValue]; 
-[__NSCFString unsignedLongValue]: unrecognized selector sent to instance 
0x76db300

expiresIn is a NSString because it was sent as quoted string in the JSON 
response from server

What is the expected output? What do you see instead?
exception thrown on completion

What version of the product are you using? On what operating system?
iOS 6 - new application

Please provide any additional information below.

Properties are assigned to GTMOAuth2Authentication properties blindly from  
JSON parsed data, so some implementations may return NSString in token response.

In my case here is the Paypal (truncated) response to 
https://api.sandbox.paypal.com/v1/identity/openidconnect/tokenservice

{
    "token_type": "Bearer",
    "expires_in": "28800",
    "refresh_token": "XXXXX",
    "id_token": "YYYYYY",
    "access_token": "ZZZZZZ"
}

Would suggest changing implementation of expiresIn to:

- (NSNumber *)expiresIn {
    id value = [self.parameters objectForKey:kOAuth2ExpiresInKey];

    if ([value isKindOfClass:[NSString class]]) {
        value = [NSNumber numberWithInteger:[value integerValue]];
    }
    return value;
}

Original issue reported on code.google.com by tbran...@gmail.com on 11 Sep 2013 at 10:20

GoogleCodeExporter commented 9 years ago
Thanks for the issue report. We've incorporated your suggestion.

https://code.google.com/p/gtm-oauth2/source/detail?r=117

Original comment by grobb...@google.com on 12 Sep 2013 at 10:37