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

Added support for external URLSession handling for having things like certificate pinning #415

Closed
wants to merge 1 commit into from

Conversation

lesmuc
Copy link

@lesmuc lesmuc commented Sep 29, 2020

Description of changes:
Added another init function that allows setting the URL Session from external. This will bring the possibility to implement the URLSessionDelegate outside the AWS Mobile AppSync SDK sources.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Added support for external URLSession handling for having things like certificate pinning
@lesmuc lesmuc changed the title Update AWSAppSyncHTTPNetworkTransport.swift Added support for external URLSession handling for having things like certificate pinning Sep 29, 2020
@palpatim
Copy link
Contributor

I agree with the use case, but I think I'd like to do this as part of a larger refactor. This class is a bit of a mess, and adding your initializer to just the "API Key" authentication type leaves a gap, (not to mention that the proposed initializer doesn't include a retryStrategy argument :) ).

I'm working on a larger PR with a new initializer like so:

public init(
    url: URL,
    urlSession: URLSession,
    authProvider: AppSyncAuthProvider,
    sendOperationIdentifiers: Bool,
    retryStrategy: AWSAppSyncRetryStrategy
)

Where AppSyncAuthProvider is an internal enum of AWSAppSyncHTTPNetworkTransport, that matches closely with the existing AWSAppSyncAuthType:

public enum AppSyncAuthProvider {
    case awsIAM(provider: AWSCredentialsProvider, endpoint: AWSEndpoint)
    case apiKey(AWSAPIKeyAuthProvider)
    case oidcToken(AWSOIDCAuthProvider)
    case amazonCognitoUserPools(AWSCognitoUserPoolsAuthProvider)
}

So to solve your use case, you'd do something like:

let session = URLSession(...with my configuration and delegate and queue)
let transport = AWSAppSyncHTTPNetworkTransport(
        url: url,
        urlSession: session,
        authProvider: .apiKey(myAPIKeyProvider),
        sendOperationIdentifiers: true,
        retryStrategy: .exponential
    )

Thoughts?

@lesmuc
Copy link
Author

lesmuc commented Oct 29, 2020

Thoughts?

Sorry for my late response and thanks for your message. Your proposal / PR looks good for me!

palpatim added a commit that referenced this pull request Nov 5, 2020
@palpatim
Copy link
Contributor

palpatim commented Nov 5, 2020

@palpatim palpatim closed this Nov 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants