diff options
author | Stas Vilchik <stas.vilchik@sonarsource.com> | 2017-09-29 15:25:20 +0200 |
---|---|---|
committer | Julien Lancelot <julien.lancelot@sonarsource.com> | 2017-10-17 17:08:53 +0200 |
commit | 94775d6f33ce5a725d0f3f229d80a0d419db2781 (patch) | |
tree | 228dd5199e0098b25776ce3ea1a381a602655c49 /server/sonar-web/src/main/js/apps | |
parent | 33eb0b2b67bcbfbbbf98fca52480b735d3b18fbc (diff) | |
download | sonarqube-94775d6f33ce5a725d0f3f229d80a0d419db2781.tar.gz sonarqube-94775d6f33ce5a725d0f3f229d80a0d419db2781.zip |
SONAR-7590 pass return_to for oauth providers
Diffstat (limited to 'server/sonar-web/src/main/js/apps')
5 files changed, 23 insertions, 8 deletions
diff --git a/server/sonar-web/src/main/js/apps/sessions/components/LoginForm.tsx b/server/sonar-web/src/main/js/apps/sessions/components/LoginForm.tsx index aafa8e68ea5..dbb5afeaa27 100644 --- a/server/sonar-web/src/main/js/apps/sessions/components/LoginForm.tsx +++ b/server/sonar-web/src/main/js/apps/sessions/components/LoginForm.tsx @@ -28,6 +28,7 @@ interface Props { onSonarCloud: boolean; identityProviders: IdentityProvider[]; onSubmit: (login: string, password: string) => void; + returnTo: string; } interface State { @@ -72,7 +73,10 @@ export default class LoginForm extends React.PureComponent<Props, State> { <h1 className="login-title text-center">{loginTitle}</h1> {this.props.identityProviders.length > 0 && ( - <OAuthProviders identityProviders={this.props.identityProviders} /> + <OAuthProviders + identityProviders={this.props.identityProviders} + returnTo={this.props.returnTo} + /> )} {this.state.collapsed ? ( diff --git a/server/sonar-web/src/main/js/apps/sessions/components/LoginFormContainer.tsx b/server/sonar-web/src/main/js/apps/sessions/components/LoginFormContainer.tsx index 1fce14f6e00..f4096338e9a 100644 --- a/server/sonar-web/src/main/js/apps/sessions/components/LoginFormContainer.tsx +++ b/server/sonar-web/src/main/js/apps/sessions/components/LoginFormContainer.tsx @@ -59,11 +59,14 @@ class LoginFormContainer extends React.PureComponent<Props, State> { this.mounted = false; } - handleSuccessfulLogin = () => { + getReturnUrl = () => { const { location } = this.props; const queryReturnTo = location.query['return_to']; - const returnTo = queryReturnTo ? `${queryReturnTo}${location.hash}` : `${getBaseUrl()}/`; - window.location.href = returnTo; + return queryReturnTo ? `${queryReturnTo}${location.hash}` : `${getBaseUrl()}/`; + }; + + handleSuccessfulLogin = () => { + window.location.href = this.getReturnUrl(); }; handleSubmit = (login: string, password: string) => { @@ -81,6 +84,7 @@ class LoginFormContainer extends React.PureComponent<Props, State> { identityProviders={identityProviders} onSonarCloud={onSonarCloud} onSubmit={this.handleSubmit} + returnTo={this.getReturnUrl()} /> ); } diff --git a/server/sonar-web/src/main/js/apps/sessions/components/OAuthProviders.tsx b/server/sonar-web/src/main/js/apps/sessions/components/OAuthProviders.tsx index 973f8b31021..ec13345fea5 100644 --- a/server/sonar-web/src/main/js/apps/sessions/components/OAuthProviders.tsx +++ b/server/sonar-web/src/main/js/apps/sessions/components/OAuthProviders.tsx @@ -25,6 +25,7 @@ import { getBaseUrl } from '../../../helpers/urls'; interface Props { formatLabel?: (name: string) => string; identityProviders: IdentityProvider[]; + returnTo: string; } export default function OAuthProviders(props: Props) { @@ -35,7 +36,10 @@ export default function OAuthProviders(props: Props) { {props.identityProviders.map(identityProvider => ( <li key={identityProvider.key}> <a - href={`${getBaseUrl()}/sessions/init/${identityProvider.key}`} + href={ + `${getBaseUrl()}/sessions/init/${identityProvider.key}` + + `?return_to=${encodeURIComponent(props.returnTo)}` + } style={{ backgroundColor: identityProvider.backgroundColor }} title={formatLabel(identityProvider.name)}> <img diff --git a/server/sonar-web/src/main/js/apps/sessions/components/__tests__/LoginForm-test.tsx b/server/sonar-web/src/main/js/apps/sessions/components/__tests__/LoginForm-test.tsx index 6f1d1ce1927..29a5edfb341 100644 --- a/server/sonar-web/src/main/js/apps/sessions/components/__tests__/LoginForm-test.tsx +++ b/server/sonar-web/src/main/js/apps/sessions/components/__tests__/LoginForm-test.tsx @@ -32,7 +32,7 @@ const identityProvider = { it('logs in with simple credentials', () => { const onSubmit = jest.fn(); const wrapper = shallow( - <LoginForm onSonarCloud={false} identityProviders={[]} onSubmit={onSubmit} /> + <LoginForm onSonarCloud={false} identityProviders={[]} onSubmit={onSubmit} returnTo="" /> ); expect(wrapper).toMatchSnapshot(); @@ -45,14 +45,14 @@ it('logs in with simple credentials', () => { it('logs in with identity provider', () => { const wrapper = shallow( - <LoginForm onSonarCloud={false} identityProviders={[identityProvider]} onSubmit={jest.fn()} /> + <LoginForm onSonarCloud={false} identityProviders={[identityProvider]} onSubmit={jest.fn()} returnTo="" /> ); expect(wrapper).toMatchSnapshot(); }); it('expands more options', () => { const wrapper = shallow( - <LoginForm onSonarCloud={false} identityProviders={[identityProvider]} onSubmit={jest.fn()} /> + <LoginForm onSonarCloud={false} identityProviders={[identityProvider]} onSubmit={jest.fn()} returnTo="" /> ); expect(wrapper).toMatchSnapshot(); diff --git a/server/sonar-web/src/main/js/apps/sessions/components/__tests__/__snapshots__/LoginForm-test.tsx.snap b/server/sonar-web/src/main/js/apps/sessions/components/__tests__/__snapshots__/LoginForm-test.tsx.snap index eb68c53aa8c..8c6b6308238 100644 --- a/server/sonar-web/src/main/js/apps/sessions/components/__tests__/__snapshots__/LoginForm-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/sessions/components/__tests__/__snapshots__/LoginForm-test.tsx.snap @@ -20,6 +20,7 @@ exports[`expands more options 1`] = ` }, ] } + returnTo="" /> <div className="text-center" @@ -55,6 +56,7 @@ exports[`expands more options 2`] = ` }, ] } + returnTo="" /> <form onSubmit={[Function]} @@ -146,6 +148,7 @@ exports[`logs in with identity provider 1`] = ` }, ] } + returnTo="" /> <div className="text-center" |