Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(API): Support for auth api oidc provider #842

Merged
merged 9 commits into from
Oct 22, 2020
Merged

fix(API): Support for auth api oidc provider #842

merged 9 commits into from
Oct 22, 2020

Conversation

wooj2
Copy link
Contributor

@wooj2 wooj2 commented Oct 21, 2020

This PR largely mirrors the following PR despite a couple naming changes:
#840

This PR allows customers to inject their own OIDC Auth Provider for use with the API category.

Customer facing call site would look like (owned by customer):

            let apiAuthProviderFactory = MyAPIAuthProviderFactory()
            let dataStorePlugin = AWSDataStorePlugin(modelRegistration: AmplifyModels())
            try Amplify.add(plugin: dataStorePlugin)
            try Amplify.add(plugin: AWSAPIPlugin(apiAuthProviderFactory: apiAuthProviderFactory))
            try Amplify.configure()

Impl ofMyAPIAuthProviderFactory (owned by customer)

class MyAPIAuthProviderFactory: APIAuthProviderFactory {
    let myAuthZeroAuthProvider = MyAuthZeroOIDCAuthProvider()
    
    override func oidcAuthProvider() -> AmplifyOIDCAuthProvider? {
        return myAuthZeroAuthProvider
    }
}

Impl of APIAuthProviderFactory (owned by AWS)

import Foundation

open class APIAuthProviderFactory {
    public init() {
    }
    open func oidcAuthProvider() -> AmplifyOIDCAuthProvider? {
        return nil
    }
}

public protocol AmplifyOIDCAuthProvider {
    func getLatestAuthToken() -> Result<String, Error>
}

In the event that we add a new authProvider type:

  • No change to customer call site
  • No change to customer owned subclass
  • Required change to Amplify owned APIAuthProviderFactory
import Foundation

open class APIAuthProviderFactory {
    public init() {
    }
    open func oidcAuthProvider() -> AmplifyOIDCAuthProvider? {
        return nil
    }
+    open func apiKeyAuthProvider() -> AmplifyAPIAuthProvider? {
+        return nil
+    }
}

public protocol AmplifyOIDCAuthProvider {
    func getLatestAuthToken() -> Result<String, Error>
}

+public protocol AmplifyAPIAuthProvider {
+    func getAPIKey() -> Result<String, Error>
+}

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@wooj2 wooj2 requested a review from lawmicha October 21, 2020 19:02
@wooj2 wooj2 marked this pull request as ready for review October 21, 2020 19:15
@wooj2 wooj2 changed the title PROTOTYPE: Concrete API Auth Provider Factory fix(API): Support for auth api oidc provider Oct 21, 2020
@wooj2 wooj2 requested a review from raphkim October 21, 2020 21:26
@wooj2 wooj2 added api Issues related to the API category core Amplify Core components labels Oct 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issues related to the API category core Amplify Core components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants