Git Product home page Git Product logo

Comments (6)

JonasGessner avatar JonasGessner commented on May 7, 2024 2

I just went through GTMAppAuthFetcherAuthorization and OIDAuthState with a bit more detail and found my answer. The auth state handles everything and loads a new access token when needed. By assigning a stateChangeDelegate to the auth state you can update the keychain item for the authorization object when needed. That's the intended way to update the keychain item, right?

from gtmappauth.

JonasGessner avatar JonasGessner commented on May 7, 2024 1

As I said in my last comment you don't have to refresh your access token manually. It's all handled automatically by the OIDAuthState (which is a part of the GTMAppAuthFetcherAuthorization). All you need to do is set the stateChangeDelegate of the authState of your authorization object and save the auth object to the keychain when the didChangeState: callback is called.

from gtmappauth.

skywalkerlw avatar skywalkerlw commented on May 7, 2024 1

Finally, i got the answer myself.

  1. we don't need explicitly to get token value and don't need to worry about token expire issue too.
  2. if you are on iOS side, instead use traditional http way, recommend to use : https://github.com/google/google-api-objectivec-client-for-rest , which could save you a ton of time

This thread tells everything: https://github.com/google/google-api-objectivec-client-for-rest/issues/75

from gtmappauth.

skywalkerlw avatar skywalkerlw commented on May 7, 2024

@JonasGessner , appreciate if you could share some code snippets

I have the same question here.

  1. How can I know my token is invalid
  2. How to request token if invalid.
  3. Do I have to jump to a Webview and log in Google account again in order to refresh my token?

from gtmappauth.

skywalkerlw avatar skywalkerlw commented on May 7, 2024

One more question

What I have done here is:
Step1: log in my Google account for the first time, and persist authorisation via:

[GTMAppAuthFetcherAuthorization saveAuthorization:_authorization
                                        toKeychainForName:kExampleAuthorizerKey]

Step2: when you come back and launch the app days/weeks later, you still can get authorization via

GTMAppAuthFetcherAuthorization* authorization =
    [GTMAppAuthFetcherAuthorization authorizationFromKeychainForName:kExampleAuthorizerKey];

. So i can get the token again via : _authorization.authState.lastTokenResponse.accessToken, However I can not make sure myself whether this token is valid or not.

My question is: when and where to set "set the stateChangeDelegate of the authState of your authorization object"

Thanks

from gtmappauth.

maztak avatar maztak commented on May 7, 2024

I faced same problem.
As two man said, we dont need to use refresh token and other method like authorization?.authState.tokenRefreshRequest().

I important thing, i think, we should get accessToken by authState?.lastTokenResponse?.accessToken. Dont save this token as the property, get it per each.

from gtmappauth.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.