Skip to content

Commit

Permalink
完善OIDC功能
Browse files Browse the repository at this point in the history
  • Loading branch information
cookieY committed Jul 7, 2022
1 parent fd49b37 commit 8f77a47
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions conf.toml.template
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ RedirectUrL = "http://127.0.0.1:8000/oidc/_token-login"
UserNameKey = "preferred_username"
RealNameKey = "name"
EmailKey = "email"
SessionKey = "session_state"
16 changes: 8 additions & 8 deletions src/handler/login/oidcLogin.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
func OidcState(c yee.Context) (err error) {

oidcAuthUrl := fmt.Sprintf(
"%s?response_type=code&client_id=%s&redirect_uri=%s&scope=%s",
"%s?response_type=code&client_id=%s&redirect_uri=%s&scope=%s&state=367126378168",
model.C.Oidc.AuthUrl,
model.C.Oidc.ClientId,
model.C.Oidc.RedirectUrL,
Expand All @@ -55,7 +55,7 @@ func OidcLogin(c yee.Context) (err error) {
}

code := c.FormValue("code")
sessionState := c.FormValue("session_state")
sessionState := c.FormValue(model.C.Oidc.SessionKey)

if code == "" || sessionState == "" {
authUri := fmt.Sprintf(
Expand Down Expand Up @@ -140,12 +140,12 @@ func getOidcUser(token *OidcToken) (userMap map[string]interface{}, err error) {

func getOidcToken(code string, session_state string) (oidc_token *OidcToken, err error) {
resp, err := http.PostForm(model.C.Oidc.TokenUrl, url.Values{
"session_state": {session_state},
"code": {code},
"client_id": {model.C.Oidc.ClientId},
"client_secret": {model.C.Oidc.ClientSecret},
"grant_type": {"authorization_code"},
"redirect_uri": {model.C.Oidc.RedirectUrL},
model.C.Oidc.SessionKey: {session_state},
"code": {code},
"client_id": {model.C.Oidc.ClientId},
"client_secret": {model.C.Oidc.ClientSecret},
"grant_type": {"authorization_code"},
"redirect_uri": {model.C.Oidc.RedirectUrL},
})
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions src/model/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type oidc struct {
TokenUrl string
UserUrl string
RedirectUrL string
SessionKey string

UserNameKey string
RealNameKey string
Expand Down

0 comments on commit 8f77a47

Please sign in to comment.