This module supports access to resources by OAuth 2.0.
Please refer to OAuth Core 2.0 details.
Types
AuthorizationError = object of Exception error*, errorDescription*, errorUri*, state*: string
AuthorizationResponse = ref object code*, state*: string
RedirectUriParseError = object of Exception
Procs
proc bearerRequest(client: AsyncHttpClient; url, accessToken: string; httpMethod = HttpGET; extraHeaders: HttpHeaders = nil; body = ""): Future[AsyncResponse] {....stackTrace: false, raises: [Exception, ValueError], tags: [RootEffect, TimeEffect, ReadIOEffect], forbids: [].}
- Send a request using the bearer token.
proc bearerRequest(client: HttpClient; url, accessToken: string; httpMethod = HttpGET; extraHeaders: HttpHeaders = nil; body = ""): Response {....raises: [KeyError, ValueError, HttpRequestError, LibraryError, Exception, OSError, SslError, IOError, TimeoutError, ProtocolError], tags: [RootEffect, ReadIOEffect, WriteIOEffect, TimeEffect], forbids: [].}
proc clientCredsGrant(client: AsyncHttpClient; url, clientid, clientsecret: string; scope: seq[string] = @[]; useBasicAuth: bool = true): Future[ AsyncResponse] {....stackTrace: false, raises: [Exception, ValueError], tags: [RootEffect, TimeEffect, ReadIOEffect], forbids: [].}
- Send a request for "Client Credentials Grant" type.
proc clientCredsGrant(client: HttpClient; url, clientid, clientsecret: string; scope: seq[string] = @[]; useBasicAuth: bool = true): Response {....raises: [ KeyError, ValueError, HttpRequestError, LibraryError, Exception, OSError, SslError, IOError, TimeoutError, ProtocolError], tags: [RootEffect, ReadIOEffect, WriteIOEffect, TimeEffect], forbids: [].}
proc getAuthorizationCodeAccessToken(client: AsyncHttpClient; url, code, clientId, clientSecret: string; redirectUri: string = ""; useBasicAuth: bool = true): Future[ AsyncResponse] {....stackTrace: false, raises: [Exception, ValueError], tags: [RootEffect, TimeEffect, ReadIOEffect], forbids: [].}
- Send the access token request for "Authorization Code Grant" type.
proc getAuthorizationCodeAccessToken(client: HttpClient; url, code, clientId, clientSecret: string; redirectUri: string = ""; useBasicAuth: bool = true): Response {....raises: [ KeyError, ValueError, HttpRequestError, LibraryError, Exception, OSError, SslError, IOError, TimeoutError, ProtocolError], tags: [RootEffect, ReadIOEffect, WriteIOEffect, TimeEffect], forbids: [].}
proc getAuthorizationCodeGrantUrl(url, clientId: string; redirectUri, state: string = ""; scope: openArray[string] = []; accessType: string = ""): string {....raises: [], tags: [], forbids: [].}
- Returns the URL for sending authorization requests in "Authorization Code Grant" type.
proc getBasicAuthorizationHeader(clientId, clientSecret: string): HttpHeaders {. ...raises: [KeyError], tags: [], forbids: [].}
- Returns a header necessary to basic authentication.
proc getBearerRequestHeader(accessToken: string): HttpHeaders {. ...raises: [KeyError], tags: [], forbids: [].}
- Returns a header necessary to bearer request.
proc getImplicitGrantUrl(url, clientId: string; redirectUri, state: string = ""; scope: openArray[string] = []; accessType: string = ""): string {. ...raises: [], tags: [], forbids: [].}
- Returns the URL for sending authorization requests in "Implicit Grant" type.
proc implicitGrant(url, clientId, state: string; html: string = ""; scope: openArray[string] = []; port: int = 8080): string {. ...deprecated, raises: [ValueError, Exception, OSError, KeyError], tags: [TimeEffect, RootEffect, ReadIOEffect], forbids: [].}
-
This method, outputs a URL for the authorization request at first.
Then, wait for the callback at "http://localhost:${port}".
When receiving the callback, check the state, returns the Uri.query as a result.
Send a request for "Implicit Grant" type. proc parseAuthorizationResponse(uri: string): AuthorizationResponse {. ...raises: [KeyError, AuthorizationError, RedirectUriParseError], tags: [], forbids: [].}
proc parseAuthorizationResponse(uri: Uri): AuthorizationResponse {. ...raises: [KeyError, AuthorizationError, RedirectUriParseError], tags: [], forbids: [].}
- Parse an authorization response of "Authorization Code Grant" added to redirect uri.
proc refreshToken(client: AsyncHttpClient; url, clientId, clientSecret, refreshToken: string; scope: seq[string] = @[]; useBasicAuth: bool = true): Future[ AsyncResponse] {....stackTrace: false, raises: [Exception, ValueError], tags: [RootEffect, TimeEffect, ReadIOEffect], forbids: [].}
- Send an update request of the access token.
proc refreshToken(client: HttpClient; url, clientId, clientSecret, refreshToken: string; scope: seq[string] = @[]; useBasicAuth: bool = true): Response {....raises: [ KeyError, ValueError, HttpRequestError, LibraryError, Exception, OSError, SslError, IOError, TimeoutError, ProtocolError], tags: [RootEffect, ReadIOEffect, WriteIOEffect, TimeEffect], forbids: [].}
proc resourceOwnerPassCredsGrant(client: AsyncHttpClient; url, clientId, clientSecret, username, password: string; scope: seq[string] = @[]; useBasicAuth: bool = true): Future[ AsyncResponse] {....stackTrace: false, raises: [Exception, ValueError], tags: [RootEffect, TimeEffect, ReadIOEffect], forbids: [].}
-
Send a request for "Resource Owner Password Credentials Grant" type.
The client MUST discard the credentials once an access token has been obtained.
-- https://tools.ietf.org/html/rfc6749#section-4.3 proc resourceOwnerPassCredsGrant(client: HttpClient; url, clientId, clientSecret, username, password: string; scope: seq[string] = @[]; useBasicAuth: bool = true): Response {....raises: [ KeyError, ValueError, HttpRequestError, LibraryError, Exception, OSError, SslError, IOError, TimeoutError, ProtocolError], tags: [RootEffect, ReadIOEffect, WriteIOEffect, TimeEffect], forbids: [].}