Skip to content

Commit

Permalink
refactor: renamed deviceCode feature to deviceFlow
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `features.deviceCode` is now `features.deviceFlow` and `deviceCodeSuccess` helper function is now
`deviceFlowSuccess`
  • Loading branch information
panva committed Sep 26, 2018
1 parent 9d7a032 commit cd57d77
Show file tree
Hide file tree
Showing 22 changed files with 57 additions and 57 deletions.
12 changes: 6 additions & 6 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ is a good starting point to get an idea of what you should provide.
- [features.claimsParameter](#featuresclaimsparameter)
- [features.clientCredentials](#featuresclientcredentials)
- [features.devInteractions](#featuresdevinteractions)
- [features.deviceCode](#featuresdevicecode)
- [features.deviceFlow](#featuresdevicecode)
- [features.discovery](#featuresdiscovery)
- [features.encryption](#featuresencryption)
- [features.frontchannelLogout](#featuresfrontchannellogout)
Expand All @@ -64,7 +64,7 @@ is a good starting point to get an idea of what you should provide.
- [cookies.names](#cookiesnames)
- [cookies.short](#cookiesshort)
- [cookies.thirdPartyCheckUrl](#cookiesthirdpartycheckurl)
- [deviceCodeSuccess](#devicecodesuccess)
- [deviceFlowSuccess](#devicecodesuccess)
- [discovery](#discovery)
- [dynamicScopes](#dynamicscopes)
- [extraClientMetadata](#extraclientmetadata)
Expand Down Expand Up @@ -734,7 +734,7 @@ Enable/disable features.
claimsParameter: false,
clientCredentials: false,
conformIdTokenClaims: true,
deviceCode: false,
deviceFlow: false,
encryption: false,
frontchannelLogout: false,
introspection: false,
Expand Down Expand Up @@ -800,7 +800,7 @@ _**default value**_:
true
```

### features.deviceCode
### features.deviceFlow

[draft-ietf-oauth-device-flow-12](https://tools.ietf.org/html/draft-ietf-oauth-device-flow-12) - Device Flow for Browserless and Input Constrained Devices

Expand Down Expand Up @@ -1271,7 +1271,7 @@ _**default value**_:
'https://cdn.rawgit.com/panva/3rdpartycookiecheck/92fead3f/start.html'
```

### deviceCodeSuccess
### deviceFlowSuccess

HTML source rendered when device code feature renders a success page for the User-Agent.

Expand All @@ -1281,7 +1281,7 @@ _**affects**_: device code success page
<br>

```js
async deviceCodeSuccess(ctx) {
async deviceFlowSuccess(ctx) {
// @param ctx - koa request context
const {
clientId, clientName, clientUri, initiateLoginUri, logoUri, policyUri, tosUri,
Expand Down
2 changes: 1 addition & 1 deletion example/adapters/bookshelf_postgresql_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
// expires_at timestamp
// );

// TODO: @madarche adapt for new storage formats and deviceCode support (opaque and jwt)
// TODO: @madarche adapt for new storage formats and deviceFlow support (opaque and jwt)

const knexCreate = require('knex'); // eslint-disable-line import/no-unresolved
const bookshelfCreate = require('bookshelf'); // eslint-disable-line import/no-unresolved
Expand Down
2 changes: 1 addition & 1 deletion example/my_adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class MyAdapter {

/**
*
* Return previously stored instance of DeviceCode. You only need this method for the deviceCode
* Return previously stored instance of DeviceCode. You only need this method for the deviceFlow
* feature
*
* @return {Promise} Promise fulfilled with either Object (when found and not dropped yet due to
Expand Down
2 changes: 1 addition & 1 deletion example/support/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ module.exports.provider = {

backchannelLogout: true, // defaults to false
claimsParameter: true, // defaults to false
deviceCode: true, // defaults to false
deviceFlow: true, // defaults to false
encryption: true, // defaults to false
frontchannelLogout: true, // defaults to false
introspection: true, // defaults to false
Expand Down
2 changes: 1 addition & 1 deletion lib/actions/authorization/device_authorization_response.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const instance = require('../../helpers/weak_cache');
module.exports = function getDeviceAuthorizationResponse(provider) {
const { DeviceCode } = provider;
const {
pkce, deviceCode: { charset, mask, deviceInfo },
pkce, deviceFlow: { charset, mask, deviceInfo },
} = instance(provider).configuration('features');

return async function deviceAuthorizationResponse(ctx, next) {
Expand Down
4 changes: 2 additions & 2 deletions lib/actions/authorization/device_user_flow_response.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const debug = require('debug')('oidc-provider:authentication:success');
const instance = require('../../helpers/weak_cache');

module.exports = provider => async function deviceVerificationResponse(ctx, next) {
const { deviceCodeSuccess } = instance(provider).configuration();
const { deviceFlowSuccess } = instance(provider).configuration();
const code = ctx.oidc.deviceCode;

Object.assign(code, {
Expand All @@ -22,7 +22,7 @@ module.exports = provider => async function deviceVerificationResponse(ctx, next

await code.save();

await deviceCodeSuccess(ctx);
await deviceFlowSuccess(ctx);

provider.emit('authorization.success', ctx);
debug('uuid=%s %o', ctx.oidc.uuid, {});
Expand Down
2 changes: 1 addition & 1 deletion lib/actions/code_verification.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module.exports = function getCodeVerification(provider) {
async function renderCodeVerification(ctx, next) {
const {
userCodeInputSource,
features: { deviceCode: { charset } },
features: { deviceFlow: { charset } },
} = instance(provider).configuration();

// TODO: generic xsrf middleware to remove this
Expand Down
2 changes: 1 addition & 1 deletion lib/actions/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ module.exports = function discoveryAction(provider) {
ctx.body.frontchannel_logout_session_supported = true;
}
}
if (config.features.deviceCode) {
if (config.features.deviceFlow) {
ctx.body.device_authorization_endpoint = ctx.oidc.urlFor('device_authorization');
}

Expand Down
2 changes: 1 addition & 1 deletion lib/adapter_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ module.exports = class AdapterTest {
.then(this.accessTokenFind.bind(this))
.then(this.accessTokenDestroy.bind(this));

if (instance(this.provider).configuration('features.deviceCode')) {
if (instance(this.provider).configuration('features.deviceFlow')) {
const dc = new (this.provider.DeviceCode)({
clientId: this.data.clientId,
grantId: this.data.grantId,
Expand Down
10 changes: 5 additions & 5 deletions lib/helpers/configuration.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ class Configuration {
throw new Error('registrationManagement is only available in conjuction with registration');
}

if (this.features.deviceCode) {
if (this.features.deviceCode.charset !== undefined) {
if (!['base-20', 'digits'].includes(this.features.deviceCode.charset)) {
if (this.features.deviceFlow) {
if (this.features.deviceFlow.charset !== undefined) {
if (!['base-20', 'digits'].includes(this.features.deviceFlow.charset)) {
throw new Error('only supported charsets are "base-20" and "digits"');
}
}
if (this.features.deviceCode.mask !== undefined) {
if (!/^[-* ]*$/.exec(this.features.deviceCode.mask)) {
if (this.features.deviceFlow.mask !== undefined) {
if (!/^[-* ]*$/.exec(this.features.deviceFlow.mask)) {
throw new Error('mask can only contain asterisk("*"), hyphen-minus("-") and space(" ") characters');
}
}
Expand Down
16 changes: 8 additions & 8 deletions lib/helpers/configuration_schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ module.exports = class ConfigurationSchema {
set(this, 'features.requestUri', { requireRequestUriRegistration: true });
}

if (get(this, 'features.deviceCode')) {
if (!this.features.deviceCode.charset) {
set(this, 'features.deviceCode.charset', 'base-20');
if (get(this, 'features.deviceFlow')) {
if (!this.features.deviceFlow.charset) {
set(this, 'features.deviceFlow.charset', 'base-20');
}
if (!this.features.deviceCode.mask) {
set(this, 'features.deviceCode.mask', '****-****');
if (!this.features.deviceFlow.mask) {
set(this, 'features.deviceFlow.mask', '****-****');
}
if (!this.features.deviceCode.deviceInfo) {
set(this, 'features.deviceCode.deviceInfo', ctx => ({
if (!this.features.deviceFlow.deviceInfo) {
set(this, 'features.deviceFlow.deviceInfo', ctx => ({
ip: ctx.ip,
userAgent: ctx.get('user-agent'),
}));
Expand Down Expand Up @@ -114,7 +114,7 @@ module.exports = class ConfigurationSchema {
this.grantTypes.add('client_credentials');
}

if (this.features.deviceCode) {
if (this.features.deviceFlow) {
this.grantTypes.add('urn:ietf:params:oauth:grant-type:device_code');
}
}
Expand Down
10 changes: 5 additions & 5 deletions lib/helpers/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,13 @@ const DEFAULTS = {
conformIdTokenClaims: true,

/*
* features.deviceCode
* features.deviceFlow
*
* title: [draft-ietf-oauth-device-flow-12](https://tools.ietf.org/html/draft-ietf-oauth-device-flow-12) - Device Flow for Browserless and Input Constrained Devices
*
* description: Enables Device Flow features
*/
deviceCode: false, // TODO: rename to deviceFlow in next major
deviceFlow: false,

/*
* features.encryption
Expand Down Expand Up @@ -886,15 +886,15 @@ const DEFAULTS = {


/*
* deviceCodeSuccess
* deviceFlowSuccess
*
* description: HTML source rendered when device code feature renders a success page for the
* User-Agent.
* affects: device code success page
*/
async deviceCodeSuccess(ctx) {
async deviceFlowSuccess(ctx) {
// @param ctx - koa request context
changeme('deviceCodeSuccess', 'customize the look of the device code success page');
changeme('deviceFlowSuccess', 'customize the look of the device code success page');
const {
clientId, clientName, clientUri, initiateLoginUri, logoUri, policyUri, tosUri, // eslint-disable-line no-unused-vars, max-len
} = ctx.oidc.client;
Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/initialize_app.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ module.exports = function initializeApp() {
post('end_session', routes.end_session, error(this, 'end_session.error'), ...endSession.post);
}

if (configuration.features.deviceCode) {
if (configuration.features.deviceFlow) {
const deviceAuthorization = getAuthorization(this, 'device_authorization');
post('device_authorization', routes.device_authorization, error(this, 'device_authorization.error'), ...deviceAuthorization);

Expand Down
2 changes: 1 addition & 1 deletion lib/shared/error_handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = function getErrorHandler(provider, eventName) {
return async function errorHandler(ctx, next) {
const {
userCodeInputSource,
features: { deviceCode: { charset } },
features: { deviceFlow: { charset } },
} = instance(provider).configuration();

try {
Expand Down
4 changes: 2 additions & 2 deletions test/configuration/adapter_test.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const client = {

describe('AdapterTest', () => {
it('passes with the default MemoryAdapter', async () => {
const provider = new Provider('http://localhost', { features: { deviceCode: true } });
const provider = new Provider('http://localhost', { features: { deviceFlow: true } });
await provider.initialize({
clients: [client],
});
Expand All @@ -20,7 +20,7 @@ describe('AdapterTest', () => {
});

it('passes with the TestAdapter', async () => {
const provider = new Provider('http://localhost', { features: { deviceCode: true } });
const provider = new Provider('http://localhost', { features: { deviceFlow: true } });
await provider.initialize({
clients: [client],
adapter: TestAdapter,
Expand Down
8 changes: 4 additions & 4 deletions test/device_code/code_verification_endpoint.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,8 @@ describe('POST code_verification endpoint w/ verification', () => {
});
afterEach(() => timekeeper.reset());
afterEach(function () {
if (i(this.provider).configuration('deviceCodeSuccess').restore) {
i(this.provider).configuration('deviceCodeSuccess').restore();
if (i(this.provider).configuration('deviceFlowSuccess').restore) {
i(this.provider).configuration('deviceFlowSuccess').restore();
}
});

Expand All @@ -312,7 +312,7 @@ describe('POST code_verification endpoint w/ verification', () => {
});

it('renders a confirmation and assigns', async function () {
const spy = sinon.spy(i(this.provider).configuration(), 'deviceCodeSuccess');
const spy = sinon.spy(i(this.provider).configuration(), 'deviceFlowSuccess');

let code = await new this.provider.DeviceCode({
clientId: 'client',
Expand Down Expand Up @@ -346,7 +346,7 @@ describe('POST code_verification endpoint w/ verification', () => {
});

it('allows for punctuation to be included and characters to be downcased', async function () {
const spy = sinon.spy(i(this.provider).configuration(), 'deviceCodeSuccess');
const spy = sinon.spy(i(this.provider).configuration(), 'deviceFlowSuccess');

let code = await new this.provider.DeviceCode({
clientId: 'client',
Expand Down
2 changes: 1 addition & 1 deletion test/device_code/device_code.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const { clone } = require('lodash');
const config = clone(require('../default.config'));

config.features = {
deviceCode: true,
deviceFlow: true,
request: false,
claimsParameter: true,
requestUri: false,
Expand Down
14 changes: 7 additions & 7 deletions test/device_code/device_code.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ const { expect } = require('chai');
const Provider = require('../../lib');
const bootstrap = require('../test_helper');

describe('configuration features.deviceCode', () => {
describe('configuration features.deviceFlow', () => {
before(bootstrap(__dirname));

it('can only be configured with digits and base-20 charset', () => {
expect(() => {
new Provider('http://localhost', { // eslint-disable-line no-new
features: {
deviceCode: {
deviceFlow: {
charset: 'digits',
},
},
Expand All @@ -19,7 +19,7 @@ describe('configuration features.deviceCode', () => {
expect(() => {
new Provider('http://localhost', { // eslint-disable-line no-new
features: {
deviceCode: {
deviceFlow: {
charset: 'base-20',
},
},
Expand All @@ -28,7 +28,7 @@ describe('configuration features.deviceCode', () => {
expect(() => {
new Provider('http://localhost', { // eslint-disable-line no-new
features: {
deviceCode: {
deviceFlow: {
charset: 'foo',
},
},
Expand All @@ -40,7 +40,7 @@ describe('configuration features.deviceCode', () => {
expect(() => {
new Provider('http://localhost', { // eslint-disable-line no-new
features: {
deviceCode: {
deviceFlow: {
mask: '*** *** ***',
},
},
Expand All @@ -49,7 +49,7 @@ describe('configuration features.deviceCode', () => {
expect(() => {
new Provider('http://localhost', { // eslint-disable-line no-new
features: {
deviceCode: {
deviceFlow: {
mask: '***-***-***',
},
},
Expand All @@ -58,7 +58,7 @@ describe('configuration features.deviceCode', () => {
expect(() => {
new Provider('http://localhost', { // eslint-disable-line no-new
features: {
deviceCode: {
deviceFlow: {
mask: '***.***.***',
},
},
Expand Down
10 changes: 5 additions & 5 deletions test/device_code/device_resume.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ describe('device interaction resume /device/:user_code/:grant/', () => {
if (this.provider.DeviceCode.findByUserCode.restore) {
this.provider.DeviceCode.findByUserCode.restore();
}
if (i(this.provider).configuration().deviceCodeSuccess.restore) {
i(this.provider).configuration().deviceCodeSuccess.restore();
if (i(this.provider).configuration().deviceFlowSuccess.restore) {
i(this.provider).configuration().deviceFlowSuccess.restore();
}
if (i(this.provider).configuration().userCodeInputSource.restore) {
i(this.provider).configuration().userCodeInputSource.restore();
Expand Down Expand Up @@ -293,7 +293,7 @@ describe('device interaction resume /device/:user_code/:grant/', () => {
});

it('should process newly established permanent sessions', async function () {
const spy = sinon.spy(i(this.provider).configuration(), 'deviceCodeSuccess');
const spy = sinon.spy(i(this.provider).configuration(), 'deviceFlowSuccess');

setup.call(this, {
scope: 'openid',
Expand All @@ -320,7 +320,7 @@ describe('device interaction resume /device/:user_code/:grant/', () => {
});

it('should process newly established temporary sessions', async function () {
const spy = sinon.spy(i(this.provider).configuration(), 'deviceCodeSuccess');
const spy = sinon.spy(i(this.provider).configuration(), 'deviceFlowSuccess');

setup.call(this, {
scope: 'openid',
Expand All @@ -347,7 +347,7 @@ describe('device interaction resume /device/:user_code/:grant/', () => {

context('consent results', () => {
it('when scope includes offline_access', async function () {
const spy = sinon.spy(i(this.provider).configuration(), 'deviceCodeSuccess');
const spy = sinon.spy(i(this.provider).configuration(), 'deviceFlowSuccess');

setup.call(this, {
scope: 'openid offline_access',
Expand Down
Loading

0 comments on commit cd57d77

Please sign in to comment.