mirror of
https://github.com/casdoor/casdoor.git
synced 2025-05-24 08:20:31 +08:00
Finish /login/oauth/authorize
This commit is contained in:
parent
f89f454e0e
commit
808e6c6283
@ -70,9 +70,7 @@ p, *, *, POST, /api/register, *, *
|
||||
p, *, *, POST, /api/login, *, *
|
||||
p, *, *, POST, /api/logout, *, *
|
||||
p, *, *, GET, /api/get-account, *, *
|
||||
p, *, *, GET, /api/auth/login, *, *
|
||||
p, *, *, GET, /api/oauth/code, *, *
|
||||
p, *, *, GET, /api/oauth/token, *, *
|
||||
p, *, *, POST, /api/login/oauth/access_token, *, *
|
||||
p, *, *, GET, /api/get-application, *, *
|
||||
p, *, *, GET, /api/get-users, *, *
|
||||
p, *, *, GET, /api/get-user, *, *
|
||||
|
@ -26,6 +26,14 @@ import (
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
func codeToResponse(code *object.Code) *Response {
|
||||
if code.Code == "" {
|
||||
return &Response{Status: "error", Msg: code.Message, Data: code.Code}
|
||||
} else {
|
||||
return &Response{Status: "ok", Msg: "", Data: code.Code}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ApiController) HandleLoggedIn(userId string, form *RequestForm) *Response {
|
||||
resp := &Response{}
|
||||
if form.Type == ResponseTypeLogin {
|
||||
|
@ -69,14 +69,6 @@ func (c *ApiController) DeleteToken() {
|
||||
c.ServeJSON()
|
||||
}
|
||||
|
||||
func codeToResponse(code *object.Code) *Response {
|
||||
if code.Code == "" {
|
||||
return &Response{Status: "error", Msg: code.Message, Data: code.Code}
|
||||
} else {
|
||||
return &Response{Status: "ok", Msg: "", Data: code.Code}
|
||||
}
|
||||
}
|
||||
|
||||
func (c *ApiController) GetOAuthToken() {
|
||||
grantType := c.Input().Get("grant_type")
|
||||
clientId := c.Input().Get("client_id")
|
||||
|
@ -81,7 +81,8 @@ func getObject(ctx *context.Context) (string, string) {
|
||||
var obj Object
|
||||
err := json.Unmarshal(body, &obj)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
//panic(err)
|
||||
return "", ""
|
||||
}
|
||||
return obj.Owner, obj.Name
|
||||
}
|
||||
|
@ -70,5 +70,5 @@ func initAPI() {
|
||||
beego.Router("/api/update-token", &controllers.ApiController{}, "POST:UpdateToken")
|
||||
beego.Router("/api/add-token", &controllers.ApiController{}, "POST:AddToken")
|
||||
beego.Router("/api/delete-token", &controllers.ApiController{}, "POST:DeleteToken")
|
||||
beego.Router("/api/oauth/token", &controllers.ApiController{}, "GET:GetOAuthToken")
|
||||
beego.Router("/api/login/oauth/access_token", &controllers.ApiController{}, "POST:GetOAuthToken")
|
||||
}
|
||||
|
@ -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>
|
||||
)
|
||||
}
|
||||
|
@ -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/>
|
||||
|
@ -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,
|
||||
};
|
||||
|
@ -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}`);
|
||||
|
Loading…
x
Reference in New Issue
Block a user