Finish /login/oauth/authorize

This commit is contained in:
Yang Luo
2021-03-20 22:34:22 +08:00
parent f89f454e0e
commit 808e6c6283
9 changed files with 22 additions and 26 deletions

View File

@ -327,14 +327,14 @@ class App extends Component {
}
isDoorPages() {
return window.location.pathname.startsWith('/login/oauth');
return window.location.pathname.startsWith("/login/oauth/authorize");
}
render() {
if (this.isDoorPages()) {
return (
<Switch>
<Route exact path="/login/oauth" render={(props) => this.renderLoginIfNotLoggedIn(<Face type={"code"} {...props} />)}/>
<Route exact path="/login/oauth/authorize" render={(props) => this.renderLoginIfNotLoggedIn(<Face type={"code"} {...props} />)}/>
</Switch>
)
}

View File

@ -247,9 +247,9 @@ class ApplicationEditPage extends React.Component {
{i18next.t("application:Face Preview")}:
</Col>
<Col span={22} >
<a style={{marginBottom: '10px'}} target="_blank" href={`/login/oauth?client_id=${this.state.application.clientId}&response_type=code&redirect_uri=${this.state.application.redirectUris[0]}&scope=read&state=casdoor`}>
<a style={{marginBottom: '10px'}} target="_blank" href={`/login/oauth/authorize?client_id=${this.state.application.clientId}&response_type=code&redirect_uri=${this.state.application.redirectUris[0]}&scope=read&state=casdoor`}>
{
`${window.location.host}/login/oauth?client_id=${this.state.application.clientId}&response_type=code&redirect_uri=${this.state.application.redirectUris[0]}&scope=read&state=casdoor`
`${window.location.host}/login/oauth/authorize?client_id=${this.state.application.clientId}&response_type=code&redirect_uri=${this.state.application.redirectUris[0]}&scope=read&state=casdoor`
}
</a>
<br/>

View File

@ -21,28 +21,23 @@ import * as Util from "./Util";
class AuthCallback extends React.Component {
constructor(props) {
super(props);
const params = new URLSearchParams(this.props.location.search);
this.state = {
classes: props,
applicationName: props.match.params.applicationName,
providerName: props.match.params.providerName,
method: props.match.params.method,
state: params.get("state"),
code: params.get("code"),
isAuthenticated: false,
isSignedUp: false,
email: ""
};
}
componentWillMount() {
const params = new URLSearchParams(this.props.location.search);
let redirectUri;
redirectUri = `${window.location.origin}/callback/${this.state.applicationName}/${this.state.providerName}/${this.state.method}`;
const body = {
application: this.state.applicationName,
provider: this.state.providerName,
code: this.state.code,
state: this.state.state,
code: params.get("code"),
state: params.get("state"),
redirectUri: redirectUri,
method: this.state.method,
};

View File

@ -91,7 +91,9 @@ class Face extends React.Component {
Util.showMessage("success", `Logged in successfully`);
Util.goToLink("/");
} else if (this.state.type === "code") {
Util.showMessage("success", `Authorization code: ${res.data}`);
const code = res.data;
Util.goToLink(`${oAuthParams.redirectUri}?code=${code}&state=${oAuthParams.state}`);
// Util.showMessage("success", `Authorization code: ${res.data}`);
}
} else {
Util.showMessage("error", `Log in failed${res.msg}`);