oauth1

This module supports access to resources by OAuth 1.0. signature method supports only HMAC-SHA1.

Please refer to OAuth Core 1.0a details.

Types

OAuth1Parameters = ref object
  realm*, consumerKey*, nonce*, signature*, signatureMethod*, timestamp*, token*,
  callback*, verifier*: string
  isIncludeVersionToHeader*: bool

Procs

proc percentEncode(str: string): string {...}{.raises: [], tags: [].}
Escape the character by using the percent encoding.
proc getSignature(HttpMethod: HttpMethod; url, body: string; params: OAuth1Parameters;
                 consumerKey, token: string): string {...}{.raises: [], tags: [].}
Generate a signature.
proc getOAuth1RequestHeader(params: OAuth1Parameters;
                           extraHeaders: HttpHeaders = nil): HttpHeaders {...}{.
    raises: [], tags: [].}
Generate the necessary header to a OAuth1 request.
proc getOAuth1RequestToken(client: AsyncHttpClient;
                          url, consumerKey, consumerSecret: string;
                          callback = "oob"; isIncludeVersionToHeader = false;
                          httpMethod = HttpPOST; extraHeaders: HttpHeaders = nil;
                          body = ""; realm: string = ""; nonce: string = ""): Future[
    AsyncResponse] {...}{.raises: [Exception, ValueError, FutureError],
                    tags: [TimeEffect, RootEffect].}
A temporary credential requests. You will receive a request token. Not the access token.

If relam parameter is not empty, add the realm to the header.
If the nonce is empty, nonce is generated by createNonce.
If isIncludeVersionToHeader is true, including the oauth_version in the header.
If the client can not receive a callback, set "oob" to callback.

proc getOAuth1RequestToken(client: HttpClient;
                          url, consumerKey, consumerSecret: string;
                          callback = "oob"; isIncludeVersionToHeader = false;
                          httpMethod = HttpPOST; extraHeaders: HttpHeaders = nil;
                          body = ""; realm: string = ""; nonce: string = ""): Response {...}{.raises: [
    ValueError, HttpRequestError, SslError, OSError, IOError, Exception, TimeoutError,
    ProtocolError, KeyError, Defect],
    tags: [TimeEffect, ReadIOEffect, WriteIOEffect, RootEffect].}
A temporary credential requests. You will receive a request token. Not the access token.

If relam parameter is not empty, add the realm to the header.
If the nonce is empty, nonce is generated by createNonce.
If isIncludeVersionToHeader is true, including the oauth_version in the header.
If the client can not receive a callback, set "oob" to callback.

proc getAuthorizeUrl(url, requestToken: string): string {...}{.raises: [], tags: [].}
It returns the url for authentication. This URL may need to access by such as a browser.
proc getOAuth1AccessToken(client: AsyncHttpClient; url, consumerKey, consumerSecret,
    requestToken, requestTokenSecret, verifier: string;
                         isIncludeVersionToHeader = false; httpMethod = HttpPOST;
                         extraHeaders: HttpHeaders = nil; body = "";
                         nonce: string = ""; realm: string = ""): Future[AsyncResponse] {...}{.
    raises: [Exception, ValueError, FutureError], tags: [TimeEffect, RootEffect].}
Get the access token.
proc getOAuth1AccessToken(client: HttpClient; url, consumerKey, consumerSecret,
    requestToken, requestTokenSecret, verifier: string;
                         isIncludeVersionToHeader = false; httpMethod = HttpPOST;
                         extraHeaders: HttpHeaders = nil; body = "";
                         nonce: string = ""; realm: string = ""): Response {...}{.raises: [
    ValueError, HttpRequestError, SslError, OSError, IOError, Exception, TimeoutError,
    ProtocolError, KeyError, Defect],
    tags: [TimeEffect, ReadIOEffect, WriteIOEffect, RootEffect].}
Get the access token.
proc oAuth1Request(client: AsyncHttpClient;
                  url, consumerKey, consumerSecret, token, tokenSecret: string;
                  isIncludeVersionToHeader = false; httpMethod = HttpGET;
                  extraHeaders: HttpHeaders = nil; body = ""; nonce: string = "";
                  realm: string = ""): Future[AsyncResponse] {...}{.
    raises: [Exception, ValueError, FutureError], tags: [TimeEffect, RootEffect].}
Send an authenticated request to access a protected resource.
proc oAuth1Request(client: HttpClient;
                  url, consumerKey, consumerSecret, token, tokenSecret: string;
                  isIncludeVersionToHeader = false; httpMethod = HttpGET;
                  extraHeaders: HttpHeaders = nil; body = ""; nonce: string = "";
                  realm: string = ""): Response {...}{.raises: [ValueError,
    HttpRequestError, SslError, OSError, IOError, Exception, TimeoutError,
    ProtocolError, KeyError, Defect],
    tags: [TimeEffect, ReadIOEffect, WriteIOEffect, RootEffect].}
Send an authenticated request to access a protected resource.