From dc168b5f235574887a33f708c10113d12c0f0aad Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Tue, 23 Aug 2016 07:30:06 +0300 Subject: [PATCH] #195: add custom description support for oauth --- src/components/auth/actions.js | 19 +++++++++++++++---- src/services/api/oauth.js | 13 ++++++++++++- src/services/authFlow/OAuthState.js | 1 + tests/components/auth/actions.test.js | 2 +- tests/services/authFlow/OAuthState.test.js | 2 ++ 5 files changed, 31 insertions(+), 6 deletions(-) diff --git a/src/components/auth/actions.js b/src/components/auth/actions.js index c5292d2..b8b5f0d 100644 --- a/src/components/auth/actions.js +++ b/src/components/auth/actions.js @@ -133,9 +133,20 @@ export function logout() { return logoutUser(); } -// TODO: move to oAuth actions? -// test request: /oauth?client_id=ely&redirect_uri=http%3A%2F%2Fely.by&response_type=code&scope=minecraft_server_session +/** + * @param {object} oauthData + * @param {string} oauthData.clientId + * @param {string} oauthData.redirectUrl + * @param {string} oauthData.responseType + * @param {string} oauthData.description + * @param {string} oauthData.scope + * @param {string} oauthData.state + * + * @return {Promise} + */ export function oAuthValidate(oauthData) { + // TODO: move to oAuth actions? + // test request: /oauth?client_id=ely&redirect_uri=http%3A%2F%2Fely.by&response_type=code&scope=minecraft_server_session&description=foo return wrapInLoader((dispatch) => oauth.validate(oauthData) .then((resp) => { @@ -175,9 +186,9 @@ export function oAuthComplete(params = {}) { dispatch(requirePermissionsAccept()); return Promise.reject(resp); - } else { - return handleOauthParamsValidation(resp); } + + return handleOauthParamsValidation(resp); }) ); } diff --git a/src/services/api/oauth.js b/src/services/api/oauth.js index 3015ae3..bb2194e 100644 --- a/src/services/api/oauth.js +++ b/src/services/api/oauth.js @@ -39,12 +39,23 @@ export default { }); } }; - +/** + * @param {object} oauthData + * @param {string} oauthData.clientId + * @param {string} oauthData.redirectUrl + * @param {string} oauthData.responseType + * @param {string} oauthData.description + * @param {string} oauthData.scope + * @param {string} oauthData.state + * + * @return {object} + */ function getOAuthRequest(oauthData) { return { client_id: oauthData.clientId, redirect_uri: oauthData.redirectUrl, response_type: oauthData.responseType, + description: oauthData.description, scope: oauthData.scope, state: oauthData.state }; diff --git a/src/services/authFlow/OAuthState.js b/src/services/authFlow/OAuthState.js index 694041a..90ef6cc 100644 --- a/src/services/authFlow/OAuthState.js +++ b/src/services/authFlow/OAuthState.js @@ -9,6 +9,7 @@ export default class OAuthState extends AbstractState { clientId: query.client_id || params.clientId, redirectUrl: query.redirect_uri, responseType: query.response_type, + description: query.description, scope: query.scope, state: query.state }).then(() => context.setState(new CompleteState())); diff --git a/tests/components/auth/actions.test.js b/tests/components/auth/actions.test.js index 505564a..4c7ff9f 100644 --- a/tests/components/auth/actions.test.js +++ b/tests/components/auth/actions.test.js @@ -100,7 +100,7 @@ describe('components/auth/actions', () => { return callThunk(oAuthComplete).then(() => { expect(request.post, 'to have a call satisfying', [ - '/api/oauth2/v1/complete?client_id=&redirect_uri=&response_type=&scope=&state=', + '/api/oauth2/v1/complete?client_id=&redirect_uri=&response_type=&description=&scope=&state=', {} ]); }); diff --git a/tests/services/authFlow/OAuthState.test.js b/tests/services/authFlow/OAuthState.test.js index 706187c..f418b55 100644 --- a/tests/services/authFlow/OAuthState.test.js +++ b/tests/services/authFlow/OAuthState.test.js @@ -26,6 +26,7 @@ describe('OAuthState', () => { client_id: 'client_id', redirect_uri: 'redirect_uri', response_type: 'response_type', + description: 'description', scope: 'scope', state: 'state' }; @@ -39,6 +40,7 @@ describe('OAuthState', () => { clientId: query.client_id, redirectUrl: query.redirect_uri, responseType: query.response_type, + description: query.description, scope: query.scope, state: query.state })