mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-01-15 00:02:30 +05:30
#21: support /oauth2/v1 on frontend
This commit is contained in:
parent
1b8333b006
commit
d6df492073
@ -70,7 +70,7 @@ function stopLoading() {
|
|||||||
/* global process: false */
|
/* global process: false */
|
||||||
if (process.env.NODE_ENV !== 'production') {
|
if (process.env.NODE_ENV !== 'production') {
|
||||||
// some shortcuts for testing on localhost
|
// some shortcuts for testing on localhost
|
||||||
window.testOAuth = () => location.href = '/oauth?client_id=ely&redirect_uri=http%3A%2F%2Fely.by&response_type=code&scope=minecraft_server_session';
|
window.testOAuth = () => location.href = '/oauth2/v1?client_id=ely&redirect_uri=http%3A%2F%2Fely.by&response_type=code&scope=minecraft_server_session';
|
||||||
window.testOAuthStatic = () => location.href = '/oauth?client_id=ely&redirect_uri=static_page_with_code&response_type=code&scope=minecraft_server_session';
|
window.testOAuthStatic = () => location.href = '/oauth2/v1?client_id=ely&redirect_uri=static_page_with_code&response_type=code&scope=minecraft_server_session';
|
||||||
window.testOAuthStaticCode = () => location.href = '/oauth?client_id=ely&redirect_uri=static_page&response_type=code&scope=minecraft_server_session';
|
window.testOAuthStaticCode = () => location.href = '/oauth2/v1?client_id=ely&redirect_uri=static_page&response_type=code&scope=minecraft_server_session';
|
||||||
}
|
}
|
||||||
|
@ -50,7 +50,7 @@ export default function routesFactory(store) {
|
|||||||
|
|
||||||
<Route path="rules" component={RulesPage} />
|
<Route path="rules" component={RulesPage} />
|
||||||
|
|
||||||
<Route path="oauth" component={OAuthInit} {...startAuthFlow} />
|
<Route path="oauth2(/:version)" component={OAuthInit} {...startAuthFlow} />
|
||||||
|
|
||||||
<Route path="auth" component={AuthPage}>
|
<Route path="auth" component={AuthPage}>
|
||||||
<Route path="/login" components={new Login()} {...startAuthFlow} />
|
<Route path="/login" components={new Login()} {...startAuthFlow} />
|
||||||
|
@ -3,7 +3,7 @@ import request from 'services/request';
|
|||||||
export default {
|
export default {
|
||||||
validate(oauthData) {
|
validate(oauthData) {
|
||||||
return request.get(
|
return request.get(
|
||||||
'/api/oauth/validate',
|
'/api/oauth2/v1/validate',
|
||||||
getOAuthRequest(oauthData)
|
getOAuthRequest(oauthData)
|
||||||
).catch(handleOauthParamsValidation);
|
).catch(handleOauthParamsValidation);
|
||||||
},
|
},
|
||||||
@ -12,7 +12,7 @@ export default {
|
|||||||
const query = request.buildQuery(getOAuthRequest(oauthData));
|
const query = request.buildQuery(getOAuthRequest(oauthData));
|
||||||
|
|
||||||
return request.post(
|
return request.post(
|
||||||
`/api/oauth/complete?${query}`,
|
`/api/oauth2/v1/complete?${query}`,
|
||||||
typeof params.accept === 'undefined' ? {} : {accept: params.accept}
|
typeof params.accept === 'undefined' ? {} : {accept: params.accept}
|
||||||
).catch((resp = {}) => {
|
).catch((resp = {}) => {
|
||||||
if (resp.statusCode === 401 && resp.error === 'access_denied') {
|
if (resp.statusCode === 401 && resp.error === 'access_denied') {
|
||||||
|
@ -122,8 +122,9 @@ export default class AuthFlow {
|
|||||||
this.run('setOAuthRequest', {});
|
this.run('setOAuthRequest', {});
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (path) { // use only first part of an url
|
switch (path) {
|
||||||
case '/oauth':
|
case '/oauth2/v1':
|
||||||
|
case '/oauth2':
|
||||||
this.setState(new OAuthState());
|
this.setState(new OAuthState());
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -56,7 +56,7 @@ describe('components/auth/actions', () => {
|
|||||||
request.get.returns(Promise.resolve(resp));
|
request.get.returns(Promise.resolve(resp));
|
||||||
|
|
||||||
return callThunk(oAuthValidate, oauthData).then(() => {
|
return callThunk(oAuthValidate, oauthData).then(() => {
|
||||||
sinon.assert.calledWith(request.get, '/api/oauth/validate');
|
sinon.assert.calledWith(request.get, '/api/oauth2/v1/validate');
|
||||||
sinon.assert.calledWith(dispatch, setClient(resp.client));
|
sinon.assert.calledWith(dispatch, setClient(resp.client));
|
||||||
sinon.assert.calledWith(dispatch, setOAuthRequest(resp.oAuth));
|
sinon.assert.calledWith(dispatch, setOAuthRequest(resp.oAuth));
|
||||||
sinon.assert.calledWith(dispatch, setScopes(resp.session.scopes));
|
sinon.assert.calledWith(dispatch, setScopes(resp.session.scopes));
|
||||||
@ -83,7 +83,7 @@ describe('components/auth/actions', () => {
|
|||||||
request.post.returns(Promise.resolve(resp));
|
request.post.returns(Promise.resolve(resp));
|
||||||
|
|
||||||
return callThunk(oAuthComplete).then(() => {
|
return callThunk(oAuthComplete).then(() => {
|
||||||
sinon.assert.calledWithMatch(request.post, /\/api\/oauth\/complete/);
|
sinon.assert.calledWithMatch(request.post, /\/api\/oauth2\/v1\/complete/);
|
||||||
sinon.assert.calledWith(dispatch, setOAuthCode({
|
sinon.assert.calledWith(dispatch, setOAuthCode({
|
||||||
success: true,
|
success: true,
|
||||||
code: '123',
|
code: '123',
|
||||||
|
@ -96,7 +96,7 @@ describe('AuthFlow.functional', () => {
|
|||||||
redirectUri: expectedRedirect
|
redirectUri: expectedRedirect
|
||||||
})});
|
})});
|
||||||
|
|
||||||
navigate('/oauth');
|
navigate('/oauth2');
|
||||||
|
|
||||||
sinon.assert.calledThrice(flow.run);
|
sinon.assert.calledThrice(flow.run);
|
||||||
sinon.assert.calledWith(flow.run.getCall(0), 'oAuthValidate');
|
sinon.assert.calledWith(flow.run.getCall(0), 'oAuthValidate');
|
||||||
|
@ -176,7 +176,8 @@ describe('AuthFlow', () => {
|
|||||||
'/change-password': LoginState,
|
'/change-password': LoginState,
|
||||||
'/oauth/permissions': LoginState,
|
'/oauth/permissions': LoginState,
|
||||||
'/oauth/finish': LoginState,
|
'/oauth/finish': LoginState,
|
||||||
'/oauth': OAuthState,
|
'/oauth2/v1': OAuthState,
|
||||||
|
'/oauth2': OAuthState,
|
||||||
'/register': RegisterState,
|
'/register': RegisterState,
|
||||||
'/recover-password': RecoverPasswordState,
|
'/recover-password': RecoverPasswordState,
|
||||||
'/recover-password/key123': RecoverPasswordState,
|
'/recover-password/key123': RecoverPasswordState,
|
||||||
@ -226,7 +227,7 @@ describe('AuthFlow', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should not handle the same request twice', () => {
|
it('should not handle the same request twice', () => {
|
||||||
const path = '/oauth';
|
const path = '/oauth2';
|
||||||
const callback = sinon.stub();
|
const callback = sinon.stub();
|
||||||
|
|
||||||
flow.handleRequest(path, () => {}, callback);
|
flow.handleRequest(path, () => {}, callback);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user