Simplify callback URL.

This commit is contained in:
Yang Luo 2021-03-21 16:05:00 +08:00
parent 6368298715
commit 1c97501016
4 changed files with 13 additions and 12 deletions

View File

@ -290,7 +290,7 @@ class App extends Component {
</Header>
<Switch>
<Route exact path="/login" render={(props) => this.renderHomeIfLoggedIn(<LoginPage onLoggedIn={this.onLoggedIn.bind(this)} {...props} />)}/>
<Route exact path="/callback/:applicationName/:providerName/:method" component={AuthCallback}/>
<Route exact path="/callback" component={AuthCallback}/>
<Route exact path="/" render={(props) => this.renderLoginIfNotLoggedIn(<HomePage account={this.state.account} onLoggedIn={this.onLoggedIn.bind(this)} {...props} />)}/>
<Route exact path="/account" render={(props) => this.renderLoginIfNotLoggedIn(<AccountPage account={this.state.account} {...props} />)}/>
<Route exact path="/organizations" render={(props) => this.renderLoginIfNotLoggedIn(<OrganizationListPage account={this.state.account} {...props} />)}/>

View File

@ -24,9 +24,6 @@ class AuthCallback extends React.Component {
super(props);
this.state = {
classes: props,
applicationName: props.match.params.applicationName,
providerName: props.match.params.providerName,
method: props.match.params.method,
};
}
@ -57,15 +54,18 @@ class AuthCallback extends React.Component {
componentWillMount() {
const params = new URLSearchParams(this.props.location.search);
const innerParams = this.getInnerParams();
let redirectUri = `${window.location.origin}/callback/${this.state.applicationName}/${this.state.providerName}/${this.state.method}`;
const applicationName = innerParams.get("application");
const providerName = innerParams.get("provider");
const method = innerParams.get("method");
let redirectUri = `${window.location.origin}/callback`;
const body = {
type: this.getResponseType(),
application: this.state.applicationName,
provider: this.state.providerName,
application: applicationName,
provider: providerName,
code: params.get("code"),
state: innerParams.get("state"),
redirectUri: redirectUri,
method: this.state.method,
method: method,
};
const oAuthParams = Util.getOAuthGetParameters(innerParams);
AuthBackend.login(body, oAuthParams)

View File

@ -43,8 +43,8 @@ export function getAuthLogo(provider) {
}
export function getAuthUrl(application, provider, method) {
const redirectUri = `${window.location.origin}/callback/${application.name}/${provider.name}/${method}`;
const state = Util.getQueryParamsToState();
const redirectUri = `${window.location.origin}/callback`;
const state = Util.getQueryParamsToState(application.name, provider.name, method);
if (provider.type === "google") {
return `${GoogleAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${GoogleAuthScope}&response_type=code&state=${state}`;
} else if (provider.type === "github") {

View File

@ -63,8 +63,9 @@ export function getOAuthGetParameters(params) {
}
}
export function getQueryParamsToState() {
const query = window.location.search;
export function getQueryParamsToState(applicationName, providerName, method) {
let query = window.location.search;
query = `${query}&application=${applicationName}&provider=${providerName}&method=${method}`;
return btoa(query);
}