This module supports access to resources by OAuth 2.0.
Please refer to OAuth Core 2.0 details.
Types
AuthorizationResponse = ref object code*, state*: string
AuthorizationError = object of Exception error*, errorDescription*, errorUri*, state*: string
RedirectUriParseError = object of Exception
Procs
proc getAuthorizationCodeGrantUrl(url, clientId: string; redirectUri, state: string = ""; scope: openArray[string] = []; accessType: string = ""): string {...}{.raises: [], tags: [].}
- Returns the URL for sending authorization requests in "Authorization Code Grant" type.
proc getImplicitGrantUrl(url, clientId: string; redirectUri, state: string = ""; scope: openArray[string] = []; accessType: string = ""): string {...}{. raises: [], tags: [].}
- Returns the URL for sending authorization requests in "Implicit Grant" type.
proc getBasicAuthorizationHeader(clientId, clientSecret: string): HttpHeaders {...}{. raises: [], tags: [].}
- Returns a header necessary to basic authentication.
proc getBearerRequestHeader(accessToken: string): HttpHeaders {...}{.raises: [], tags: [].}
- Returns a header necessary to bearer request.
proc getAuthorizationCodeAccessToken(client: AsyncHttpClient; url, code, clientId, clientSecret: string; redirectUri: string = ""; useBasicAuth: bool = true): Future[AsyncResponse] {...}{. raises: [Exception, ValueError, FutureError], tags: [RootEffect, TimeEffect].}
- 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: [ ValueError, HttpRequestError, SslError, OSError, IOError, Exception, TimeoutError, ProtocolError, KeyError, Defect], tags: [ReadIOEffect, WriteIOEffect, RootEffect, TimeEffect].}
- Send the access token request for "Authorization Code Grant" type.
proc generateState(): string {...}{.raises: [], tags: [TimeEffect].}
- Generate a state.
proc parseAuthorizationResponse(uri: Uri): AuthorizationResponse {...}{. raises: [KeyError, AuthorizationError, RedirectUriParseError], tags: [].}
- Parse an authorization response of "Authorization Code Grant" added to redirect uri.
proc parseAuthorizationResponse(uri: string): AuthorizationResponse {...}{. raises: [KeyError, AuthorizationError, RedirectUriParseError], tags: [].}
proc authorizationCodeGrant(client: AsyncHttpClient; authorizeUrl, accessTokenRequestUrl, clientId, clientSecret: string; html: string = ""; scope: seq[string] = @[]; port: int = 8080): Future[ AsyncResponse] {...}{.deprecated, raises: [Exception, ValueError, FutureError], tags: [TimeEffect, RootEffect, ReadIOEffect].}
-
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, and request an access token to the server.
Returns the request result of the access token.
Send a request for "Authorization Code Grant" type.
proc authorizationCodeGrant(client: HttpClient; authorizeUrl, accessTokenRequestUrl, clientId, clientSecret: string; html: string = ""; scope: seq[string] = @[]; port: int = 8080): Response {...}{.deprecated, raises: [ Exception, ValueError, FutureError, UnpackError, OSError, IndexError, KeyError, HttpRequestError, SslError, IOError, TimeoutError, ProtocolError, Defect], tags: [TimeEffect, RootEffect, ReadIOEffect, WriteIOEffect].}
-
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, and request an access token to the server.
Returns the request result of the access token.
Send a request for "Authorization Code Grant" type.
proc implicitGrant(url, clientId: string; html: string = ""; scope: openArray[string] = []; port: int = 8080): string {...}{.deprecated, raises: [ Exception, ValueError, FutureError, UnpackError, OSError, IndexError, KeyError], tags: [TimeEffect, RootEffect, ReadIOEffect].}
-
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 resourceOwnerPassCredsGrant(client: AsyncHttpClient; url, clientId, clientSecret, username, password: string; scope: seq[string] = @[]; useBasicAuth: bool = true): Future[AsyncResponse] {...}{. raises: [Exception, ValueError, FutureError], tags: [RootEffect, TimeEffect].}
-
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: [ ValueError, HttpRequestError, SslError, OSError, IOError, Exception, TimeoutError, ProtocolError, KeyError, Defect], tags: [ReadIOEffect, WriteIOEffect, RootEffect, TimeEffect].}
-
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 clientCredsGrant(client: AsyncHttpClient; url, clientid, clientsecret: string; scope: seq[string] = @[]; useBasicAuth: bool = true): Future[ AsyncResponse] {...}{.raises: [Exception, ValueError, FutureError], tags: [RootEffect, TimeEffect].}
- Send a request for "Client Credentials Grant" type.
proc clientCredsGrant(client: HttpClient; url, clientid, clientsecret: string; scope: seq[string] = @[]; useBasicAuth: bool = true): Response {...}{.raises: [ ValueError, HttpRequestError, SslError, OSError, IOError, Exception, TimeoutError, ProtocolError, KeyError, Defect], tags: [ReadIOEffect, WriteIOEffect, RootEffect, TimeEffect].}
- Send a request for "Client Credentials Grant" type.
proc refreshToken(client: AsyncHttpClient; url, clientId, clientSecret, refreshToken: string; scope: seq[string] = @[]; useBasicAuth: bool = true): Future[ AsyncResponse] {...}{.raises: [Exception, ValueError, FutureError], tags: [RootEffect, TimeEffect].}
- 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: [ ValueError, HttpRequestError, SslError, OSError, IOError, Exception, TimeoutError, ProtocolError, KeyError, Defect], tags: [ReadIOEffect, WriteIOEffect, RootEffect, TimeEffect].}
- Send an update request of the access token.
proc bearerRequest(client: AsyncHttpClient; url, accessToken: string; httpMethod = HttpGET; extraHeaders: HttpHeaders = nil; body = ""): Future[ AsyncResponse] {...}{.raises: [Exception, ValueError, FutureError], tags: [RootEffect, TimeEffect].}
- Send a request using the bearer token.
proc bearerRequest(client: HttpClient; url, accessToken: string; httpMethod = HttpGET; extraHeaders: HttpHeaders = nil; body = ""): Response {...}{.raises: [ ValueError, HttpRequestError, SslError, OSError, IOError, Exception, TimeoutError, ProtocolError, KeyError, Defect], tags: [ReadIOEffect, WriteIOEffect, RootEffect, TimeEffect].}
- Send a request using the bearer token.