@ndustrial/contxt-sdk
Advanced tools
Comparing version 0.0.29 to 0.0.30
@@ -0,1 +1,8 @@ | ||
## [v0.0.30](http://github.com/ndustrialio/contxt-sdk-js/tree/v0.0.30) (2018-08-20) | ||
**Changed** | ||
* Started normalizing Silent Authentication errors from Auth0 in the Auth0WebAuth session type to match Axios errors. | ||
* Additionally, started logging the user out when one of these errors is encountered. | ||
## [v0.0.29](http://github.com/ndustrialio/contxt-sdk-js/tree/v0.0.29) (2018-08-16) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "@ndustrial/contxt-sdk", | ||
"version": "0.0.29", | ||
"version": "0.0.30", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -323,4 +323,5 @@ import auth0 from 'auth0-js'; | ||
/** | ||
* Gets up to date session info. Will get an updated session/tokens if the previous session has | ||
* already expired. | ||
* Gets up to date session info. Will get an updated session/tokens if the | ||
* previous session has already expired. Will log the user out if an error | ||
* from Auth0 indicates the session cannot continue without re-authentication. | ||
* | ||
@@ -343,13 +344,31 @@ * @returns {Promise} | ||
.catch((err) => { | ||
if (!(err.response && err.response.status)) { | ||
const wrapperError = new Error( | ||
let errorToThrow = err; | ||
if ( | ||
err.error && | ||
[ | ||
'consent_required', | ||
'interaction_required', | ||
'login_required' | ||
].indexOf(err.error) > -1 | ||
) { | ||
errorToThrow = new Error('Unauthorized'); | ||
errorToThrow.response = { | ||
data: { | ||
...err, | ||
code: 401 | ||
}, | ||
status: 401 | ||
}; | ||
this.logOut(); | ||
} else if (!(err.response && err.response.status)) { | ||
errorToThrow = new Error( | ||
'There was a problem getting new session info. Please check your configuration settings.' | ||
); | ||
wrapperError.fromSdk = true; | ||
wrapperError.originalError = err; | ||
throw wrapperError; | ||
errorToThrow.fromSdk = true; | ||
errorToThrow.originalError = err; | ||
} | ||
throw err; | ||
throw errorToThrow; | ||
}); | ||
@@ -356,0 +375,0 @@ } |
@@ -906,6 +906,48 @@ import auth0 from 'auth0-js'; | ||
context('when there is an error getting the session info', function() { | ||
let logOut; | ||
beforeEach(function() { | ||
this.sandbox.stub(Auth0WebAuth.prototype, '_loadSession'); | ||
logOut = this.sandbox.stub(Auth0WebAuth.prototype, 'logOut'); | ||
}); | ||
it('throws a 401 and logs the user out if Auth0 requires the session to be re-authenticated', function() { | ||
const errorType = faker.random.arrayElement([ | ||
'consent_required', | ||
'interaction_required', | ||
'login_required' | ||
]); | ||
const originalError = { | ||
error: errorType, | ||
error_description: { | ||
consent_required: 'Consent required', | ||
interaction_required: 'Interaction required', | ||
login_required: 'Login required' | ||
}[errorType] | ||
}; | ||
const expectedError = new Error('Unauthorized'); | ||
expectedError.response = { | ||
data: { | ||
code: 401, | ||
error: originalError.error, | ||
error_description: originalError.error_description | ||
}, | ||
status: 401 | ||
}; | ||
this.sandbox | ||
.stub(Auth0WebAuth.prototype, '_checkSession') | ||
.rejects(originalError); | ||
const auth0WebAuth = new Auth0WebAuth(sdk); | ||
const promise = auth0WebAuth._getUpdatedSessionInfo(); | ||
return promise.then(expect.fail).catch((error) => { | ||
expect(error.message).to.equal('Unauthorized'); | ||
expect(error.response).to.deep.equal(expectedError.response); | ||
expect(logOut).to.be.calledOnce; | ||
}); | ||
}); | ||
it('throws a human readable error when unable to reach the server', function() { | ||
@@ -912,0 +954,0 @@ const originalError = new Error(faker.hacker.phrase()); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
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
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
1385700
17780