Browse Source

SONAR-7590 pass return_to for oauth providers

tags/6.7-RC1
Stas Vilchik 6 years ago
parent
commit
94775d6f33

+ 5
- 1
server/sonar-web/src/main/js/apps/sessions/components/LoginForm.tsx View File

@@ -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 ? (

+ 7
- 3
server/sonar-web/src/main/js/apps/sessions/components/LoginFormContainer.tsx View File

@@ -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()}
/>
);
}

+ 5
- 1
server/sonar-web/src/main/js/apps/sessions/components/OAuthProviders.tsx View File

@@ -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

+ 3
- 3
server/sonar-web/src/main/js/apps/sessions/components/__tests__/LoginForm-test.tsx View File

@@ -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();


+ 3
- 0
server/sonar-web/src/main/js/apps/sessions/components/__tests__/__snapshots__/LoginForm-test.tsx.snap View File

@@ -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"

Loading…
Cancel
Save