mirror of
https://github.com/OpenBankProject/OBP-TypeScript.git
synced 2026-02-06 10:48:07 +00:00
Merge pull request #10 from mark-tesobe/develop
FIX: empty authorization header
This commit is contained in:
commit
11284ae640
@ -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",
|
||||
|
||||
@ -236,7 +236,6 @@ const getDirectLoginToken = async (
|
||||
config: APIClientConfig
|
||||
): Promise<string> => {
|
||||
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;
|
||||
};
|
||||
|
||||
@ -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,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user