Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add flag __enableIdPInitiatedLogin to enable idp initiated logins #708

Merged
merged 1 commit into from
Mar 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/web-auth/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,14 @@ WebAuth.prototype.parseHash = function(options, cb) {
*/
WebAuth.prototype.validateAuthenticationResponse = function(options, parsedHash, cb) {
var _this = this;
options.__enableIdPInitiatedLogin =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor but ... I wonder if you shouldn't call this something else since it encompasses 2 different use cases here? Like options.__bypassStateChecking or thereabouts?

options.__enableIdPInitiatedLogin || options.__enableImpersonation;
var state = parsedHash.state;
var transaction = this.transactionManager.getStoredTransaction(state);
var transactionState = options.state || (transaction && transaction.state) || null;

var transactionStateMatchesState = transactionState === state;
var shouldBypassStateChecking = !state && !transactionState && options.__enableImpersonation;
var shouldBypassStateChecking = !state && !transactionState && options.__enableIdPInitiatedLogin;

if (!shouldBypassStateChecking && !transactionStateMatchesState) {
return cb({
Expand Down
78 changes: 78 additions & 0 deletions test/web-auth/web-auth.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -531,6 +531,54 @@ describe('auth0.WebAuth', function() {
);
});

it('should bypass state checking when options.__enableIdPInitiatedLogin is set to true and there is no state in the hash and in the transaction', function(
done
) {
var webAuth = new WebAuth({
domain: 'wptest.auth0.com',
redirectUri: 'http://example.com/callback',
clientID: 'gYSNlU4YC4V1YPdqq8zPQcup6rJw1Mbt',
responseType: 'token',
__disableExpirationCheck: true
});
TransactionManager.prototype.getStoredTransaction.restore();
stub(TransactionManager.prototype, 'getStoredTransaction', function() {
return null;
});

var data = webAuth.parseHash(
{
nonce: 'asfd',
hash: '#access_token=asldkfjahsdlkfjhasd&id_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlF6RTROMFpCTTBWRFF6RTJSVVUwTnpJMVF6WTFNelE0UVRrMU16QXdNRUk0UkRneE56RTRSZyJ9.eyJpc3MiOiJodHRwczovL3dwdGVzdC5hdXRoMC5jb20vIiwic3ViIjoiYXV0aDB8NTVkNDhjNTdkNWIwYWQwMjIzYzQwOGQ3IiwiYXVkIjoiZ1lTTmxVNFlDNFYxWVBkcXE4elBRY3VwNnJKdzFNYnQiLCJleHAiOjE0ODI5NjkwMzEsImlhdCI6MTQ4MjkzMzAzMSwibm9uY2UiOiJhc2ZkIn0.PPoh-pITcZ8qbF5l5rMZwXiwk5efbESuqZ0IfMUcamB6jdgLwTxq-HpOT_x5q6-sO1PBHchpSo1WHeDYMlRrOFd9bh741sUuBuXdPQZ3Zb0i2sNOAC2RFB1E11mZn7uNvVPGdPTg-Y5xppz30GSXoOJLbeBszfrVDCmPhpHKGGMPL1N6HV-3EEF77L34YNAi2JQ-b70nFK_dnYmmv0cYTGUxtGTHkl64UEDLi3u7bV-kbGky3iOOCzXKzDDY6BBKpCRTc2KlbrkO2A2PuDn27WVv1QCNEFHvJN7HxiDDzXOsaUmjrQ3sfrHhzD7S9BcCRkekRfD9g95SKD5J0Fj8NA&token_type=Bearer&refresh_token=kajshdgfkasdjhgfas',
__enableIdPInitiatedLogin: true
},
function(err, data) {
expect(err).to.be(null);
expect(data).to.eql({
accessToken: 'asldkfjahsdlkfjhasd',
idToken: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlF6RTROMFpCTTBWRFF6RTJSVVUwTnpJMVF6WTFNelE0UVRrMU16QXdNRUk0UkRneE56RTRSZyJ9.eyJpc3MiOiJodHRwczovL3dwdGVzdC5hdXRoMC5jb20vIiwic3ViIjoiYXV0aDB8NTVkNDhjNTdkNWIwYWQwMjIzYzQwOGQ3IiwiYXVkIjoiZ1lTTmxVNFlDNFYxWVBkcXE4elBRY3VwNnJKdzFNYnQiLCJleHAiOjE0ODI5NjkwMzEsImlhdCI6MTQ4MjkzMzAzMSwibm9uY2UiOiJhc2ZkIn0.PPoh-pITcZ8qbF5l5rMZwXiwk5efbESuqZ0IfMUcamB6jdgLwTxq-HpOT_x5q6-sO1PBHchpSo1WHeDYMlRrOFd9bh741sUuBuXdPQZ3Zb0i2sNOAC2RFB1E11mZn7uNvVPGdPTg-Y5xppz30GSXoOJLbeBszfrVDCmPhpHKGGMPL1N6HV-3EEF77L34YNAi2JQ-b70nFK_dnYmmv0cYTGUxtGTHkl64UEDLi3u7bV-kbGky3iOOCzXKzDDY6BBKpCRTc2KlbrkO2A2PuDn27WVv1QCNEFHvJN7HxiDDzXOsaUmjrQ3sfrHhzD7S9BcCRkekRfD9g95SKD5J0Fj8NA',
idTokenPayload: {
iss: 'https://wptest.auth0.com/',
sub: 'auth0|55d48c57d5b0ad0223c408d7',
aud: 'gYSNlU4YC4V1YPdqq8zPQcup6rJw1Mbt',
exp: 1482969031,
iat: 1482933031,
nonce: 'asfd'
},
appState: null,
refreshToken: 'kajshdgfkasdjhgfas',
state: null,
expiresIn: null,
tokenType: 'Bearer',
scope: null
});

expect(TransactionManager.prototype.getStoredTransaction.calledOnce).to.be.ok();

done();
}
);
});
it('should bypass state checking when options.__enableImpersonation is set to true and there is no state in the hash and in the transaction', function(
done
) {
Expand Down Expand Up @@ -660,6 +708,36 @@ describe('auth0.WebAuth', function() {
); // eslint-disable-line
});

it('should fail with an invalid state (available transaction with __enableIdPInitiatedLogin:true)', function(
done
) {
var webAuth = new WebAuth({
domain: 'mdocs.auth0.com',
redirectUri: 'http://example.com/callback',
clientID: '0HP71GSd6PuoRYJ3p',
responseType: 'token'
});
TransactionManager.prototype.getStoredTransaction.restore();
stub(TransactionManager.prototype, 'getStoredTransaction', function() {
return {
state: 'not-123'
};
});

var data = webAuth.parseHash(
{
hash: '#state=123&access_token=VjubIMBmpgQ2W2&id_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImtpZCI6IlF6RTROMFpCTTBWRFF6RTJSVVUwTnpJMVF6WTFNelE0UVRrMU16QXdNRUk0UkRneE56RTRSZyJ9.eyJpc3MiOiJodHRwczovL3dwdGVzdC5hdXRoMC5jb20vIiwic3ViIjoiYXV0aDB8NTVkNDhjNTdkNWIwYWQwMjIzYzQwOGQ3IiwiYXVkIjoiZ1lTTmxVNFlDNFYxWVBkcXE4elBRY3VwNnJKdzFNYnQiLCJleHAiOjE0ODI5NjkwMzEsImlhdCI6MTQ4MjkzMzAzMSwibm9uY2UiOiJhc2ZkIn0.PPoh-pITcZ8qbF5l5rMZwXiwk5efbESuqZ0IfMUcamB6jdgLwTxq-HpOT_x5q6-sO1PBHchpSo1WHeDYMlRrOFd9bh741sUuBuXdPQZ3Zb0i2sNOAC2RFB1E11mZn7uNvVPGdPTg-Y5xppz30GSXoOJLbeBszfrVDCmPhpHKGGMPL1N6HV-3EEF77L34YNAi2JQ-b70nFK_dnYmmv0cYTGUxtGTHkl64UEDLi3u7bV-kbGky3iOOCzXKzDDY6BBKpCRTc2KlbrkO2A2PuDn27WVv1QCNEFHvJN7HxiDDzXOsaUmjrQ3sfrHhzD7S9BcCRkekRfD9g95SKD5J0Fj8NA&token_type=Bearer&refresh_token=kajshdgfkasdjhgfas',
__enableIdPInitiatedLogin: true
},
function(err, data) {
expect(err).to.eql({
error: 'invalid_token',
errorDescription: '`state` does not match.'
});
done();
}
); // eslint-disable-line
});
it('should fail with an invalid state (available transaction with __enableImpersonation:true)', function(
done
) {
Expand Down