Merge pull request #8949 from reasonerjt/oidc-err-1.8

Handle error on OIDC callback -- cherry-pick to 1.8 branch
This commit is contained in:
stonezdj(Daojun Zhang) 2019-09-05 15:18:36 +08:00 committed by GitHub
commit 98bf819ca7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -82,6 +82,15 @@ func (oc *OIDCController) Callback() {
oc.SendBadRequestError(errors.New("State mismatch"))
return
}
errorCode := oc.Ctx.Request.URL.Query().Get("error")
if errorCode != "" {
errorDescription := oc.Ctx.Request.URL.Query().Get("error_description")
log.Errorf("OIDC callback returned error: %s - %s", errorCode, errorDescription)
oc.SendBadRequestError(errors.Errorf("OIDC callback returned error: %s - %s", errorCode, errorDescription))
return
}
code := oc.Ctx.Request.URL.Query().Get("code")
ctx := oc.Ctx.Request.Context()
token, err := oidc.ExchangeToken(ctx, code)