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

deprecate rejectWithResponse=false #1985

Merged
merged 1 commit into from
Oct 29, 2019
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
9 changes: 9 additions & 0 deletions addon/authenticators/devise.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { isEmpty } from '@ember/utils';
import { run } from '@ember/runloop';
import { merge, assign as emberAssign } from '@ember/polyfills';
import { computed } from '@ember/object';
import { deprecate } from '@ember/application/deprecations';
import BaseAuthenticator from './base';
import fetch from 'fetch';

Expand Down Expand Up @@ -140,6 +141,14 @@ export default BaseAuthenticator.extend({
authenticate(identification, password) {
return new Promise((resolve, reject) => {
const useResponse = this.get('rejectWithResponse');

if (!useResponse) {
deprecate('Ember Simple Auth: The default value of false for the rejectWithResponse property should no longer be relied on; instead set the property to true to enable the future behavior.', false, {
id: `ember-simple-auth.authenticator.no-reject-with-response`,
until: '2.0.0'
});
}

const { resourceName, identificationAttributeName, tokenAttributeName } = this.getProperties('resourceName', 'identificationAttributeName', 'tokenAttributeName');
const data = {};
data[resourceName] = { password };
Expand Down
8 changes: 8 additions & 0 deletions addon/authenticators/oauth2-password-grant.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,14 @@ export default BaseAuthenticator.extend({
const data = { 'grant_type': 'password', username: identification, password };
const serverTokenEndpoint = this.get('serverTokenEndpoint');
const useResponse = this.get('rejectWithResponse');

if (!useResponse) {
deprecate('Ember Simple Auth: The default value of false for the rejectWithResponse property should no longer be relied on; instead set the property to true to enable the future behavior.', false, {
id: `ember-simple-auth.authenticator.no-reject-with-response`,
until: '2.0.0'
});
}

const scopesString = makeArray(scope).join(' ');
if (!isEmpty(scopesString)) {
data.scope = scopesString;
Expand Down
15 changes: 15 additions & 0 deletions tests/unit/authenticators/devise-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { tryInvoke } from '@ember/utils';
import { registerDeprecationHandler } from '@ember/debug';
import {
describe,
beforeEach,
Expand Down Expand Up @@ -62,6 +63,20 @@ describe('DeviseAuthenticator', () => {
});
});

it('shows a deprecation warning when rejectWithResponse is not enabled', function() {
authenticator.set('rejectWithResponse', false);

let warnings = [];
registerDeprecationHandler((message, options, next) => {
warnings.push(message);
next(message, options);
});
marcoow marked this conversation as resolved.
Show resolved Hide resolved

return authenticator.authenticate('identification', 'password').then(() => {
expect(warnings[0]).to.eq('Ember Simple Auth: The default value of false for the rejectWithResponse property should no longer be relied on; instead set the property to true to enable the future behavior.');
});
});

describe('when the authentication request is successful', function() {
beforeEach(function() {
server.post('/users/sign_in', () => [201, { 'Content-Type': 'application/json' }, '{ "token": "secret token!", "email": "[email protected]" }']);
Expand Down
21 changes: 21 additions & 0 deletions tests/unit/authenticators/oauth2-password-grant-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,27 @@ describe('OAuth2PasswordGrantAuthenticator', () => {
authenticator.authenticate('username', 'password', ['public', 'private']);
});

it('shows a deprecation warning when rejectWithResponse is not enabled', function(done) {
authenticator.set('rejectWithResponse', false);
server.post('/token', (request) => {
let { requestBody } = request;
let { scope } = parsePostData(requestBody);
expect(scope).to.eql('public private');
done();
});

let warnings = [];
registerDeprecationHandler((message, options, next) => {
warnings.push(message);
next(message, options);
});
marcoow marked this conversation as resolved.
Show resolved Hide resolved

server.post('/token', () => done());
authenticator.authenticate('username', 'password');

expect(warnings[1]).to.eq('Ember Simple Auth: The default value of false for the rejectWithResponse property should no longer be relied on; instead set the property to true to enable the future behavior.');
});

describe('when the authentication request is successful', function() {
beforeEach(function() {
server.post('/token', () => [200, { 'Content-Type': 'application/json' }, '{ "access_token": "secret token!" }']);
Expand Down