google / GTMAppAuth

Apple platforms SDK for using AppAuth with Google libraries.
Apache License 2.0
379 stars 198 forks source link

V2 to V4 pod migration: GTMAppAuthFetcherAuthorization(fromKeychainForName:) replacement #234

Closed ashokds closed 11 months ago

ashokds commented 11 months ago

Question

What is the new interface for GTMAppAuthFetcherAuthorization(fromKeychainForName: ) in 4.0.0?

Looks like AuthSessionStore is the way to go based on ChangeLog. How to create and use KeychainStore for proper retrieval, need direction to sample-code to find the recommended way to handle code-update?

Keychain Store Readme

Details

I'm migrating GTMAppAuth from 2.0.0 to 4.0.0 and have following code in my app to retrieve the session info with the keychain name:

    // From `2.0.0` based
    var authorizer: GTMFetcherAuthorizationProtocol? {
       GTMAppAuthFetcherAuthorization(fromKeychainForName: myKeychainName)
    }

   // To `4.0.0` based - Getting error with following code when `init` `GTMSessionFetcherAuthorizer` is invoked.
    var authorizer: GTMSessionFetcherAuthorizer? {
        GTMSessionFetcherAuthorizer(fromKeychainForName: myKeychainName)
    }

Relevant section from current podfile.lock after performing the update and clean pods/project build:

PODS:
  - AppAuth (1.6.2):
    - AppAuth/Core (= 1.6.2)
    - AppAuth/ExternalUserAgent (= 1.6.2)
  - AppAuth/Core (1.6.2)
  - AppAuth/ExternalUserAgent (1.6.2):
    - AppAuth/Core

    ...

  - GoogleSignIn (7.1.0-fac-eap-1.0.0):
    - AppAuth (~> 1.6)
    - AppCheckCore (~> 10.18)
    - GTMAppAuth (~> 4.0)
    - GTMSessionFetcher/Core (< 4.0, >= 1.1)

    ... 
  - GTMAppAuth (4.0.0):
    - AppAuth/Core (~> 1.6)
    - GTMSessionFetcher/Core (< 4.0, >= 2.1)

Looking at the changelog entry for v3.0.0:

Are we supposed to use @objc public func retrieveAuthSession(withItemName itemName: String) throws -> AuthSession { from the GTMAppAuth/KeychainStore.swift?

Yes, please share the snippet to create and handle the KeychainStore object. If not, Please guide, which corresponding method to use to retrieve the authorization?

The old interface is:

/*! @brief Category to support serialization and deserialization of
        @c GTMAppAuthFetcherAuthorization in the format used by GTMAppAuth.
 */
@interface GTMAppAuthFetcherAuthorization (Keychain)

/*! @brief Attempts to create a @c GTMAppAuthFetcherAuthorization from data stored in the keychain
        in GTMAppAuth format.
    @param keychainItemName The keychain name.
    @return A @c GTMAppAuthFetcherAuthorization object, or nil.
 */
+ (nullable GTMAppAuthFetcherAuthorization *)
    authorizationFromKeychainForName:(NSString *)keychainItemName;

To Reproduce Steps to reproduce the behavior:

  1. Use v2.0.0 GTMAppAuth pod and use `` interface in the app code say following:
var authorizer: GTMFetcherAuthorizationProtocol? {
      GTMAppAuthFetcherAuthorization(fromKeychainForName: myKeychainName)
}
  1. Perform pod update GTMAppAuth to v4.0.0
  2. Notice the errors:
    • 'any GTMSessionFetcherAuthorizer' cannot be constructed because it has no accessible initializers

Expected behavior Migration guide from v2.0.0 to v.3.0.0 and v4.0.0 would help in resolution of this error.

Screenshots If applicable, add screenshots to help explain your problem.

Environment

Additional context Swift based App using COCOAPODS: 1.13.0

ashokds commented 11 months ago

Please update the label to Question instead of bug.

mdmathias commented 11 months ago

@ashokds take a look at the example iOS app. It shows several examples that you should be able to use or modify. I'm going to close this issue for now, but please do reply with questions if you have any!