mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-16 05:43:50 +08:00
Simplify callback URL.
This commit is contained in:
@ -290,7 +290,7 @@ class App extends Component {
|
|||||||
</Header>
|
</Header>
|
||||||
<Switch>
|
<Switch>
|
||||||
<Route exact path="/login" render={(props) => this.renderHomeIfLoggedIn(<LoginPage onLoggedIn={this.onLoggedIn.bind(this)} {...props} />)}/>
|
<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="/" 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="/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} />)}/>
|
<Route exact path="/organizations" render={(props) => this.renderLoginIfNotLoggedIn(<OrganizationListPage account={this.state.account} {...props} />)}/>
|
||||||
|
@ -24,9 +24,6 @@ class AuthCallback extends React.Component {
|
|||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
classes: props,
|
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() {
|
componentWillMount() {
|
||||||
const params = new URLSearchParams(this.props.location.search);
|
const params = new URLSearchParams(this.props.location.search);
|
||||||
const innerParams = this.getInnerParams();
|
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 = {
|
const body = {
|
||||||
type: this.getResponseType(),
|
type: this.getResponseType(),
|
||||||
application: this.state.applicationName,
|
application: applicationName,
|
||||||
provider: this.state.providerName,
|
provider: providerName,
|
||||||
code: params.get("code"),
|
code: params.get("code"),
|
||||||
state: innerParams.get("state"),
|
state: innerParams.get("state"),
|
||||||
redirectUri: redirectUri,
|
redirectUri: redirectUri,
|
||||||
method: this.state.method,
|
method: method,
|
||||||
};
|
};
|
||||||
const oAuthParams = Util.getOAuthGetParameters(innerParams);
|
const oAuthParams = Util.getOAuthGetParameters(innerParams);
|
||||||
AuthBackend.login(body, oAuthParams)
|
AuthBackend.login(body, oAuthParams)
|
||||||
|
@ -43,8 +43,8 @@ export function getAuthLogo(provider) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function getAuthUrl(application, provider, method) {
|
export function getAuthUrl(application, provider, method) {
|
||||||
const redirectUri = `${window.location.origin}/callback/${application.name}/${provider.name}/${method}`;
|
const redirectUri = `${window.location.origin}/callback`;
|
||||||
const state = Util.getQueryParamsToState();
|
const state = Util.getQueryParamsToState(application.name, provider.name, method);
|
||||||
if (provider.type === "google") {
|
if (provider.type === "google") {
|
||||||
return `${GoogleAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${GoogleAuthScope}&response_type=code&state=${state}`;
|
return `${GoogleAuthUri}?client_id=${provider.clientId}&redirect_uri=${redirectUri}&scope=${GoogleAuthScope}&response_type=code&state=${state}`;
|
||||||
} else if (provider.type === "github") {
|
} else if (provider.type === "github") {
|
||||||
|
@ -63,8 +63,9 @@ export function getOAuthGetParameters(params) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getQueryParamsToState() {
|
export function getQueryParamsToState(applicationName, providerName, method) {
|
||||||
const query = window.location.search;
|
let query = window.location.search;
|
||||||
|
query = `${query}&application=${applicationName}&provider=${providerName}&method=${method}`;
|
||||||
return btoa(query);
|
return btoa(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user