AuthenticatedURLSession

public final class AuthenticatedURLSession

AuthenticatedURLSession wraps a User to allow Bearer authenticated requests and the use of URLSessionDataTask

  • Initializes a AuthenticatedURLSession for given user and session configuration

    Declaration

    Swift

    public init(user: User, configuration: URLSessionConfiguration)

    Parameters

    user

    The User object of whom tokens are used to authenticate requests.

    configuration

    The URLSessionConfiguration object used for creating URLSession.

  • Creates a task that retrieves the contents of a URL based on the specified URL request object. The request will be authenticated and the request will refresh on 401 failure.

    Declaration

    Swift

    public func dataTask(with request: URLRequest) -> URLSessionDataTask

    Parameters

    request

    A URL request object that will be authenticated.

  • Creates a task that retrieves the contents of a URL based on the specified URL request object, and calls a handler upon completion. The request will be authenticated and the request will refresh on 401 failure.

    Declaration

    Swift

    public func dataTask(with request: URLRequest,
                         completionHandler: @escaping (Data?, URLResponse?, Error?) -> Void) -> URLSessionDataTask

    Parameters

    request

    A URL request object that will be authenticated.

    completionHandler

    The completion handler to call when the load request is complete.