Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to integrate GTMOAuth2 with RestKit on iOS?
    primarykey
    data
    text
    <p>I'm trying get <a href="http://restkit.org/" rel="nofollow">RestKit</a> (version 0.10.2) to authenticate with OAuth2. I'm using <a href="http://code.google.com/p/gtm-oauth2/" rel="nofollow">GTMOAuth2</a> to handle the OAuth interactions.</p> <p>I've successfully gotten GTMOAuth2 to sign me in and make a request to the api I'm using. I've also managed to get RestKit to make a request with my access token with this:</p> <pre class="lang-c prettyprint-override"><code>- (void)setRKAuthorizationToken:(NSString *)authorizationToken { RKObjectManager* objectManager = [RKObjectManager sharedManager]; NSString* authHeader = [NSString stringWithFormat:@"Bearer %@", authorizationToken]; [objectManager.client setValue:authHeader forHTTPHeaderField:@"Authorization"]; } </code></pre> <p>In this code sample I am manually setting the HTTP header because RestKit's support for OAuth2 sets the header as <code>Authorization: OAuth2 &lt;accessToken&gt;</code> instead of <code>Authorization: Bearer &lt;accessToken&gt;</code>.</p> <p>Anyway, this works great until the access token needs to be refreshed with the refresh token.</p> <p>What I'd really like to do is tell RestKit to use <code>GTMOAuth2Authentication</code>'s <code>- (BOOL)authorizeRequest:(NSMutableURLRequest *)request;</code> as it automatically fetches a new access token with the refresh token when the access token expires.</p> <p>BTW, RestKit is <a href="https://github.com/RestKit/RestKit/issues/643" rel="nofollow">phasing it's support for OAuth</a>; authorizing requests with a third-party library is the suggested approach. I <a href="https://github.com/RestKit/RestKit/pull/696" rel="nofollow">asked for an example</a> and the response pointed me in the direction of classes to subclass, which are in the <code>development</code> branch.</p> <p>So, the question is: Have you successfully integrated RestKit 0.10.x with GTMOAuth2 or know how to accomplish this?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload