mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 12:30:19 +08:00
feat: add userinfo endpoint (#447)
* feat: add userinfo endpoint Signed-off-by: 0x2a <stevesough@gmail.com> * feat: add scope support Signed-off-by: 0x2a <stevesough@gmail.com> * fix: modify the endpoint of discovery Signed-off-by: 0x2a <stevesough@gmail.com>
This commit is contained in:
@ -43,6 +43,7 @@ func AutoSigninFilter(ctx *context.Context) {
|
||||
|
||||
userId := fmt.Sprintf("%s/%s", claims.User.Owner, claims.User.Name)
|
||||
setSessionUser(ctx, userId)
|
||||
setSessionOidc(ctx, claims.Scope, claims.Audience[0])
|
||||
return
|
||||
}
|
||||
|
||||
@ -81,5 +82,6 @@ func AutoSigninFilter(ctx *context.Context) {
|
||||
|
||||
setSessionUser(ctx, fmt.Sprintf("%s/%s", claims.Owner, claims.Name))
|
||||
setSessionExpire(ctx, claims.ExpiresAt.Unix())
|
||||
setSessionOidc(ctx, claims.Scope, claims.Audience[0])
|
||||
}
|
||||
}
|
||||
|
@ -97,6 +97,18 @@ func setSessionExpire(ctx *context.Context, ExpireTime int64) {
|
||||
ctx.Input.CruSession.SessionRelease(ctx.ResponseWriter)
|
||||
}
|
||||
|
||||
func setSessionOidc(ctx *context.Context, scope string, aud string) {
|
||||
err := ctx.Input.CruSession.Set("scope", scope)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
err = ctx.Input.CruSession.Set("aud", aud)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
ctx.Input.CruSession.SessionRelease(ctx.ResponseWriter)
|
||||
}
|
||||
|
||||
func parseBearerToken(ctx *context.Context) string {
|
||||
header := ctx.Request.Header.Get("Authorization")
|
||||
tokens := strings.Split(header, " ")
|
||||
|
@ -50,6 +50,7 @@ func initAPI() {
|
||||
beego.Router("/api/get-app-login", &controllers.ApiController{}, "GET:GetApplicationLogin")
|
||||
beego.Router("/api/logout", &controllers.ApiController{}, "POST:Logout")
|
||||
beego.Router("/api/get-account", &controllers.ApiController{}, "GET:GetAccount")
|
||||
beego.Router("/api/userinfo", &controllers.ApiController{}, "GET:GetUserinfo")
|
||||
beego.Router("/api/unlink", &controllers.ApiController{}, "POST:Unlink")
|
||||
beego.Router("/api/get-saml-login", &controllers.ApiController{}, "GET:GetSamlLogin")
|
||||
beego.Router("/api/acs", &controllers.ApiController{}, "POST:HandleSamlLogin")
|
||||
|
Reference in New Issue
Block a user