OIDC: Accept gin context in handler #782

This commit is contained in:
Timo Volkmann 2021-12-10 10:40:39 +01:00
parent f1fe2c20d6
commit b28931d8e7
2 changed files with 4 additions and 18 deletions

View file

@ -29,10 +29,7 @@ func AuthEndpoints(router *gin.RouterGroup) {
callbackError(c, err.Error(), http.StatusInternalServerError)
return
}
handle := openIdConnect.AuthUrlHandler()
handle(c.Writer, c.Request)
return
openIdConnect.AuthCodeUrlHandler(c)
})
router.GET(oidc.RedirectPath, func(c *gin.Context) {

View file

@ -108,8 +108,9 @@ func state() string {
return rnd.UUID()
}
func (c *Client) AuthUrlHandler() http.HandlerFunc {
return rp.AuthURLHandler(state, c)
func (c *Client) AuthCodeUrlHandler(ctx *gin.Context) {
handle := rp.AuthURLHandler(state, c)
handle(ctx.Writer, ctx.Request)
}
func (c *Client) CodeExchangeUserInfo(ctx *gin.Context) (oidc.UserInfo, error) {
@ -117,7 +118,6 @@ func (c *Client) CodeExchangeUserInfo(ctx *gin.Context) (oidc.UserInfo, error) {
userinfoClosure := func(w http.ResponseWriter, r *http.Request, tokens *oidc.Tokens, state string, rp rp.RelyingParty, info oidc.UserInfo) {
log.Debugf("oidc: UserInfo: %s %s %s %s %s", info.GetEmail(), info.GetSubject(), info.GetNickname(), info.GetName(), info.GetPreferredUsername())
userinfo = info
}
@ -144,14 +144,3 @@ func (c *Client) CodeExchangeUserInfo(ctx *gin.Context) (oidc.UserInfo, error) {
return userinfo, nil
}
func (c *Client) IsAvailable() error {
if c == nil {
return errors.New("oidc: not initialized")
}
_, err := client.Discover(c.Issuer(), httpclient.Client(c.debug))
if err != nil {
return err
}
return nil
}