in proxy/handler/oauth2/oauth2_handler.go [50:85]
func (oa *Handler) Handle(chain *handler.Chain, inv *invocation.Invocation, cb invocation.ResponseCallBack) {
if auth != nil && auth.GrantType == "authorization_code" {
if req, ok := inv.Args.(*http.Request); ok {
state := req.FormValue("state")
if state != Random && state != "" {
WriteBackErr(ErrInvalidState, http.StatusUnauthorized, cb)
return
}
code := req.FormValue("code")
if code == "" {
WriteBackErr(ErrInvalidCode, http.StatusUnauthorized, cb)
return
}
accessToken, err := getToken(code, cb)
if err != nil {
openlog.Error("authorization error: " + err.Error())
WriteBackErr(ErrInvalidToken, http.StatusUnauthorized, cb)
return
}
if auth.Authenticate != nil {
err = auth.Authenticate(accessToken, req)
if err != nil {
openlog.Error("authentication error: " + err.Error())
WriteBackErr(ErrInvalidAuth, http.StatusUnauthorized, cb)
return
}
}
}
}
chain.Next(inv, func(r *invocation.Response) {
cb(r)
})
}