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

Remove email param in cross auth login #692

Merged
merged 1 commit into from
Mar 5, 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
5 changes: 4 additions & 1 deletion src/web-auth/cross-origin-authentication.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ CrossOriginAuthentication.prototype.login = function(options, cb) {
var _this = this;
var theWindow = windowHelper.getWindow();
var url = urljoin(this.baseOptions.rootUrl, '/co/authenticate');
options.username = options.username || options.email;
delete options.email;
Copy link
Member

Choose a reason for hiding this comment

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

Why move the code up here? Just so it email can be deleted?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes


var authenticateBody = {
client_id: options.clientID || this.baseOptions.clientID,
username: options.username || options.email
username: options.username
};
if (options.password) {
authenticateBody.password = options.password;
Expand Down
37 changes: 36 additions & 1 deletion test/web-auth/cross-origin-authentication.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ describe('auth0.WebAuth.crossOriginAuthentication', function() {
storage.setItem.restore();
}
});
it('should call /co/authenticate and redirect to /authorize with login_ticket', function() {
it('should call /co/authenticate and redirect to /authorize with login_ticket using `username`', function() {
stub(request, 'post', function(url) {
expect(url).to.be('https://me.auth0.com/co/authenticate');
return new RequestMock({
Expand Down Expand Up @@ -79,6 +79,41 @@ describe('auth0.WebAuth.crossOriginAuthentication', function() {
anotherOption: 'foobar'
});
});
it('should call /co/authenticate and redirect to /authorize with login_ticket using `email`', function() {
stub(request, 'post', function(url) {
expect(url).to.be('https://me.auth0.com/co/authenticate');
return new RequestMock({
body: {
client_id: '...',
credential_type: 'password',
username: 'me@example.com',
password: '123456'
},
headers: {
'Content-Type': 'application/json'
},
cb: function(cb) {
cb(null, {
body: {
login_ticket: 'a_login_ticket',
co_verifier: 'co_verifier',
co_id: 'co_id'
}
});
}
});
});
this.co.login({
email: 'me@example.com',
password: '123456',
anotherOption: 'foobar'
});
expect(this.webAuthSpy.authorize.getCall(0).args[0]).to.be.eql({
username: 'me@example.com',
loginTicket: 'a_login_ticket',
anotherOption: 'foobar'
});
});
it('should call /co/authenticate and call `webMessageHandler.run` when popup:true', function(
done
) {
Expand Down