Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions oauth-1.0a.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,24 @@ declare class OAuth {
/**
* Sign a request.
*/
authorize(request: OAuth.RequestOptions, token?: OAuth.Token): OAuth.Authorization;
authorize(request: OAuth.RequestOptions, token?: OAuth.Token): Promise<OAuth.Authorization>;

/**
* Generate the oauth signature (i.e. oauth_signature).
*/
getSignature(request: OAuth.RequestOptions, token_secret: string | undefined, oauth_data: OAuth.Data): string;
getSignature(request: OAuth.RequestOptions, token_secret: string | undefined, oauth_data: OAuth.Data): Promise<string>;

/**
* Generate the body signature (i.e. oauth_body_hash).
*/
getBodyHash(request: OAuth.RequestOptions, token_secret: string | undefined): string;
getBodyHash(request: OAuth.RequestOptions, token_secret: string | undefined): Promise<string>;

/**
* Encode the request attributes.
*
* Base String = "<Method>&<Base Url>&<ParameterString>"
*/
getBaseString(request: OAuth.RequestOptions, oauth_data: OAuth.Data): string;
getBaseString(request: OAuth.RequestOptions, oauth_data: OAuth.Data): Promise<string>;

/**
* Encode the oauth data and the request parameter,
Expand Down Expand Up @@ -140,7 +140,7 @@ declare namespace OAuth {
/**
* Method used to hash the the OAuth and form/querystring data.
*/
export type HashFunction = (base_string: string, key: string) => string;
export type HashFunction = (base_string: string, key: string) => Promise<string>;

/**
* Authorization header.
Expand Down
16 changes: 8 additions & 8 deletions oauth-1.0a.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function OAuth(opts) {
this.signature_method = opts.signature_method || 'PLAINTEXT';

if(this.signature_method == 'PLAINTEXT' && !opts.hash_function) {
opts.hash_function = function(base_string, key) {
opts.hash_function = async function(base_string, key) {
return key;
}
}
Expand All @@ -59,7 +59,7 @@ function OAuth(opts) {
* @param {Object} key and secret token
* @return {Object} OAuth Authorized data
*/
OAuth.prototype.authorize = function(request, token) {
OAuth.prototype.authorize = async function(request, token) {
var oauth_data = {
oauth_consumer_key: this.consumer.key,
oauth_nonce: this.getNonce(),
Expand All @@ -81,10 +81,10 @@ OAuth.prototype.authorize = function(request, token) {
}

if(request.includeBodyHash) {
oauth_data.oauth_body_hash = this.getBodyHash(request, token.secret)
oauth_data.oauth_body_hash = await this.getBodyHash(request, token.secret)
}

oauth_data.oauth_signature = this.getSignature(request, token.secret, oauth_data);
oauth_data.oauth_signature = await this.getSignature(request, token.secret, oauth_data);

return oauth_data;
};
Expand All @@ -96,22 +96,22 @@ OAuth.prototype.authorize = function(request, token) {
* @param {Object} oauth_data OAuth data
* @return {String} Signature
*/
OAuth.prototype.getSignature = function(request, token_secret, oauth_data) {
return this.hash_function(this.getBaseString(request, oauth_data), this.getSigningKey(token_secret));
OAuth.prototype.getSignature = async function(request, token_secret, oauth_data) {
return await this.hash_function(this.getBaseString(request, oauth_data), this.getSigningKey(token_secret));
};

/**
* Create a OAuth Body Hash
* @param {Object} request data
*/
OAuth.prototype.getBodyHash = function(request, token_secret) {
OAuth.prototype.getBodyHash = async function(request, token_secret) {
var body = typeof request.data === 'string' ? request.data : JSON.stringify(request.data)

if (!this.body_hash_function) {
throw new Error('body_hash_function option is required');
}

return this.body_hash_function(body, this.getSigningKey(token_secret))
return await this.body_hash_function(body, this.getSigningKey(token_secret))
};

/**
Expand Down
Loading