diff --git a/package.json b/package.json index 6fec58a..b0a5c9f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "obp-typescript", - "version": "1.0.33", + "version": "1.0.36", "license": "Apache-2.0", "scripts": { "build": "tsc --declaration && tsc-alias", diff --git a/src/api/client.ts b/src/api/client.ts index 6bf88e0..e32ec1f 100644 --- a/src/api/client.ts +++ b/src/api/client.ts @@ -236,7 +236,6 @@ const getDirectLoginToken = async ( config: APIClientConfig ): Promise => { if (!config.authentication) { - console.warn("Authentication is not set."); return ""; } const loginUri = config.baseUri + "/my/logins/direct"; @@ -244,12 +243,13 @@ const getDirectLoginToken = async ( const password = config.authentication.password; const consumerKey = config.authentication.consumerKey; const directLogin = `DirectLogin username=${username},password=${password},consumer_key=${consumerKey}`; + const authorization = directLogin ? { Authorization: directLogin } : {}; const response = JSON.parse( ( await superagent .post(loginUri) .set("Content-Type", "application/json") - .set("Authorization", directLogin) + .set(authorization) ).text ); return "DirectLogin token=" + response.token; @@ -284,6 +284,23 @@ const getOauthHeader = async ( return header; }; +/** + * Get the Authorization header. + * + * @param header - The OAuth header value + * @returns An {object} value + * + * + * @private + */ +const getValidHeader = (header: string): any => { + if (header) { + return { Authorization: header, "Content-Type": "application/json" }; + } else { + return { "Content-Type": "application/json" }; + } +}; + /** * Send a GET HTTP request and returns a response. * @@ -303,7 +320,7 @@ export const getRequest = async ( return ( await superagent .get(pathUri) - .set("Authorization", header) + .set(getValidHeader(header)) .catch((error) => error.response) ).body; }; @@ -330,7 +347,7 @@ export const postRequest = async ( return ( await superagent .post(pathUri) - .set("Authorization", header) + .set(getValidHeader(header)) .send(body) .catch((error) => error.response) ).body; @@ -358,7 +375,7 @@ export const putRequest = async ( return ( await superagent .put(pathUri) - .set("Authorization", header) + .set(getValidHeader(header)) .send(body) .catch((error) => error.response) ).body; @@ -385,7 +402,7 @@ export const deleteRequest = async ( return ( await superagent .delete(pathUri) - .set("Authorization", header) + .set(getValidHeader(header)) .catch((error) => error.response) ).body; }; diff --git a/src/auth/index.ts b/src/auth/index.ts index f44d369..ace14b2 100644 --- a/src/auth/index.ts +++ b/src/auth/index.ts @@ -111,8 +111,6 @@ export class OAuth { * @public */ authHeader(pathUri: string, method: string): string { - if (!this.config.accessToken) console.warn("Access token is not set."); - if (this.config.accessToken) { return this.instance.authHeader( pathUri,