mirror of
https://github.com/Permissionless-Software-Foundation/bch-js.git
synced 2026-09-21 16:51:59 -07:00
fix(basic auth): Fixing some bugs around basic auth
This commit is contained in:
+1
-1
@@ -65,7 +65,7 @@ class BCHJS {
|
|||||||
// Generate a Basic Authentication token from an auth password
|
// Generate a Basic Authentication token from an auth password
|
||||||
this.authToken = ""
|
this.authToken = ""
|
||||||
if (this.authPass) {
|
if (this.authPass) {
|
||||||
console.log(`bch-js initialized with authPass: ${this.authPass}`)
|
// console.log(`bch-js initialized with authPass: ${this.authPass}`)
|
||||||
// Generate the header for Basic Authentication.
|
// Generate the header for Basic Authentication.
|
||||||
const combined = `fullstackcash:${this.authPass}`
|
const combined = `fullstackcash:${this.authPass}`
|
||||||
var base64Credential = Buffer.from(combined).toString("base64")
|
var base64Credential = Buffer.from(combined).toString("base64")
|
||||||
|
|||||||
@@ -272,9 +272,7 @@ class RawTransactions {
|
|||||||
txids: txid,
|
txids: txid,
|
||||||
verbose: verbose
|
verbose: verbose
|
||||||
},
|
},
|
||||||
headers: {
|
headers: _this.axiosOptions.headers
|
||||||
authorization: `Token ${this.apiToken}`
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const response = await axios(options)
|
const response = await axios(options)
|
||||||
|
|
||||||
@@ -347,9 +345,7 @@ class RawTransactions {
|
|||||||
data: {
|
data: {
|
||||||
hexes: hex
|
hexes: hex
|
||||||
},
|
},
|
||||||
headers: {
|
headers: _this.axiosOptions.headers
|
||||||
authorization: `Token ${this.apiToken}`
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const response = await axios(options)
|
const response = await axios(options)
|
||||||
|
|
||||||
|
|||||||
+17
-6
@@ -18,17 +18,28 @@ class TokenType1 {
|
|||||||
constructor(config) {
|
constructor(config) {
|
||||||
this.restURL = config.restURL
|
this.restURL = config.restURL
|
||||||
this.apiToken = config.apiToken
|
this.apiToken = config.apiToken
|
||||||
|
this.authToken = config.authToken
|
||||||
|
|
||||||
|
if (this.authToken) {
|
||||||
|
// Add Basic Authentication token to the authorization header.
|
||||||
|
this.axiosOptions = {
|
||||||
|
headers: {
|
||||||
|
authorization: this.authToken
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Add JWT token to the authorization header.
|
||||||
|
this.axiosOptions = {
|
||||||
|
headers: {
|
||||||
|
authorization: `Token ${this.apiToken}`
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
addy = new Address(config)
|
addy = new Address(config)
|
||||||
this.Script = new Script()
|
this.Script = new Script()
|
||||||
|
|
||||||
this.axios = axios
|
this.axios = axios
|
||||||
// Add JWT token to the authorization header.
|
|
||||||
this.axiosOptions = {
|
|
||||||
headers: {
|
|
||||||
authorization: `Token ${this.apiToken}`
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Instantiate the transaction builder.
|
// Instantiate the transaction builder.
|
||||||
TransactionBuilder.setAddress(addy)
|
TransactionBuilder.setAddress(addy)
|
||||||
|
|||||||
+14
-4
@@ -13,11 +13,21 @@ class Utils {
|
|||||||
this.restURL = config.restURL
|
this.restURL = config.restURL
|
||||||
this.apiToken = config.apiToken
|
this.apiToken = config.apiToken
|
||||||
this.slpParser = slpParser
|
this.slpParser = slpParser
|
||||||
|
this.authToken = config.authToken
|
||||||
|
|
||||||
// Add JWT token to the authorization header.
|
if (this.authToken) {
|
||||||
this.axiosOptions = {
|
// Add Basic Authentication token to the authorization header.
|
||||||
headers: {
|
this.axiosOptions = {
|
||||||
authorization: `Token ${this.apiToken}`
|
headers: {
|
||||||
|
authorization: this.authToken
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Add JWT token to the authorization header.
|
||||||
|
this.axiosOptions = {
|
||||||
|
headers: {
|
||||||
|
authorization: `Token ${this.apiToken}`
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user