OAuth2Requestable

open class OAuth2Requestable

Abstract base class for OAuth2 authorization as well as client registration classes.

  • Set to true to log all the things. false by default. Use "verbose": bool in settings or assign logger yourself.

    Declaration

    Swift

    open var verbose: Bool { get set }
  • The logger being used. Auto-assigned to a debug logger if you set verbose to true or false.

    Declaration

    Swift

    open var logger: OAuth2Logger?
  • Base initializer.

    Declaration

    Swift

    public init(verbose: Bool)
  • Designated initializer.

    Declaration

    Swift

    public init(logger: OAuth2Logger?)

    Parameters

    logger

    An optional OAuth2Logger instance to use

  • The instance’s current session, creating one by the book if necessary. Defaults to using an ephemeral session, you can use sessionConfiguration and/or sessionDelegate to affect how the session is configured.

    Declaration

    Swift

    open var session: URLSession { get }
  • The configuration to use when creating session. Uses an +ephemeralSessionConfiguration() if nil.

    Declaration

    Swift

    open var sessionConfiguration: URLSessionConfiguration? { get set }
  • URL session delegate that should be used for the NSURLSession the instance uses for requests.

    Declaration

    Swift

    open var sessionDelegate: URLSessionDelegate? { get set }
  • The instance’s OAuth2RequestPerformer, defaults to using OAuth2DataTaskRequestPerformer which uses URLSession.dataTask().

    Declaration

    Swift

    open var requestPerformer: OAuth2RequestPerformer?
  • Perform the supplied request and call the callback with the response JSON dict or an error. This method is intended for authorization calls, not for data calls outside of the OAuth2 dance.

    This implementation uses the shared NSURLSession and executes a data task. If the server responds with an error, this will be converted into an error according to information supplied in the response JSON (if availale).

    The callback returns a response object that is easy to use, like so:

    perform(request: req) { response in
        do {
            let data = try response.responseData()
            // do what you must with `data` as Data and `response.response` as HTTPURLResponse
        }
        catch let error {
            // the request failed because of `error`
        }
    }
    

    Easy, right?

    Declaration

    Swift

    open func perform(request: URLRequest, callback: @escaping ((OAuth2Response) -> Void))

    Parameters

    request

    The request to execute

    callback

    The callback to call when the request completes/fails. Looks terrifying, see above on how to use it

  • Can be called to immediately abort the currently running authorization request, if it was started by perform(request:callback:).

    Declaration

    Swift

    func abortTask() -> Bool

    Return Value

    A bool indicating whether a task was aborted or not

  • Parse string-only JSON from NSData.

    Declaration

    Swift

    open func parseJSON(_ data: Data) throws -> OAuth2JSON

    Parameters

    data

    NSData returned from the call, assumed to be JSON with string-values only.

    Return Value

    An OAuth2JSON instance

  • Parse a query string into a dictionary of String: String pairs.

    If you’re retrieving a query or fragment from NSURLComponents, use the percentEncoded## variant as the others automatically perform percent decoding, potentially messing with your query string.

    Declaration

    Swift

    public final class func params(fromQuery query: String) -> OAuth2StringDict

    Parameters

    fromQuery

    The query string you want to have parsed

    Return Value

    A dictionary full of strings with the key-value pairs found in the query