@salling-group/auth
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -7,7 +7,7 @@ const createInstance = require('./instance'); | ||
* | ||
* @param {string} email The email for the JWT. | ||
* @param {string} issuer The issuer for the JWT. | ||
* @param {string} secret The secret for the JWT. | ||
*/ | ||
function jwt(email, secret) { | ||
return createInstance(jwtBuilder(email, secret)); | ||
function jwt(issuer, secret) { | ||
return createInstance(jwtBuilder(issuer, secret)); | ||
} | ||
@@ -14,0 +14,0 @@ |
@@ -7,7 +7,7 @@ const signJWT = require('./sign'); | ||
* | ||
* @param email The email to use. | ||
* @param issuer The issuer to use. | ||
* @param secret The secret to use. | ||
* @returns {function(config: Object): string} | ||
*/ | ||
function jwtBuilder(email, secret) { | ||
function jwtBuilder(issuer, secret) { | ||
return (config) => { | ||
@@ -18,3 +18,3 @@ const url = new URL(config.url, config.baseURL); | ||
config.params = {}; | ||
return `JWT ${signJWT(email, config.method, decodeURIComponent(url.pathname + url.search), secret)}`; | ||
return `JWT ${signJWT(issuer, config.method, decodeURIComponent(url.pathname + url.search), secret)}`; | ||
}; | ||
@@ -21,0 +21,0 @@ } |
@@ -10,7 +10,7 @@ const builders = require('./builders'); | ||
if (type === 'jwt') { | ||
const { email, secret } = auth; | ||
if (!email || !secret) { | ||
throw new Error('JWT authentication requires an email and a secret.'); | ||
const { email, issuer, secret } = auth; | ||
if (!(email || issuer) || !secret) { | ||
throw new Error('JWT authentication requires an issuer and a secret.'); | ||
} | ||
return builders.jwtBuilder(email, secret); | ||
return builders.jwtBuilder(issuer || email, secret); | ||
} else if (type === 'bearer') { | ||
@@ -17,0 +17,0 @@ const { token } = auth; |
@@ -7,3 +7,3 @@ const crypto = require('crypto'); | ||
* | ||
* @param {string} email The email to use. | ||
* @param {string} issuer The issuer to use. | ||
* @param {string} method The HTTP method on the path. | ||
@@ -14,3 +14,3 @@ * @param {string} path The path. This should include the query parameters. Hash is not supported. | ||
*/ | ||
function signJWT(email, method, path, key) { | ||
function signJWT(issuer, method, path, key) { | ||
const header = { | ||
@@ -22,3 +22,3 @@ 'alg': 'HS256', | ||
'exp': Date.now() / 1000 | 0, | ||
'iss': email, | ||
'iss': issuer, | ||
'mth': method, | ||
@@ -25,0 +25,0 @@ 'sub': path, |
@@ -18,3 +18,3 @@ const axios = require('axios'); | ||
* @param {String} options.auth.type The type of authentication. | ||
* @param {String} [options.auth.email] The email used for JWT. | ||
* @param {String} [options.auth.issuer] The issuer used for JWT. | ||
* @param {String} [options.auth.secret] The secret used for JWT. | ||
@@ -21,0 +21,0 @@ * @param {String} [options.auth.token] The token used for Bearer. |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"author": { | ||
@@ -9,0 +9,0 @@ "name": "Salling Group - API Developers", |
@@ -41,3 +41,3 @@ # Salling Group API Authentication | ||
|`token`|`String`|If `type` is `'bearer'`.|The token associared with the bearer token credentials.| | ||
|`email`|`String`|If `type` is `'jwt'`.|The email associated with the JWT credentials.| | ||
|`issuer`|`String`|If `type` is `'jwt'`.|The issuer associated with the JWT credentials.| | ||
|`secret`|`String`|If `type` is `'jwt'`.|The secret associated with the JWT credentials.| | ||
@@ -68,3 +68,3 @@ | ||
'type': 'bearer', | ||
'email': 'my_email', | ||
'issuer': 'my_issuer', | ||
'secret': 'my_secret', | ||
@@ -71,0 +71,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46892
13
1078
1