// Authorization code endpoint func oauthAuthorize(w http.ResponseWriter, r *http.Request, ctx *Context) (err error) { resp := server.NewResponse() defer resp.Close() if ar := server.HandleAuthorizeRequest(resp, r); ar != nil { link := fmt.Sprintf("/authorize?response_type=%s&client_id=%s&redirect_uri=%s&state=%s&scope=%s", ar.Type, ar.Client.GetId(), url.QueryEscape(ar.RedirectUri), ar.State, ar.Scope) // HANDLE LOGIN PAGE HERE if ctx.User == nil { ctx.Referer = link return loginForm(w, r, ctx) // resp.SetRedirect(reverse("login") + "?referer=" + reverse("authorize")) } else { if r.Method == "GET" { scopes, err := backends.LoadScopes() if err != nil { return err } return T("authorize.html").Execute(w, map[string]interface{}{ "link": link, "response_type": ar.Type, "scopes": scopes, "client": ar.Client.(*models.Client), "ctx": ctx, }) } if r.PostForm.Get("authorize") == "1" { ar.UserData = ctx.User.Uid ar.Authorized = true server.FinishAuthorizeRequest(resp, r, ar) } else { resp.SetRedirect(reverse("welcome")) } } } if resp.IsError && resp.InternalError != nil { log.Printf("authorize ERROR: %s\n", resp.InternalError) } // if !resp.IsError { // resp.Output["uid"] = ctx.User.Uid // } debugf("oauthAuthorize resp: %v", resp) osin.OutputJSON(resp, w, r) return resp.InternalError }
func scopesForm(w http.ResponseWriter, req *http.Request, ctx *Context) (err error) { if ctx.User == nil || ctx.User.IsExpired() || !ctx.User.IsKeeper() { http.Redirect(w, req, reverse("login"), http.StatusTemporaryRedirect) return nil } scopes, err := backends.LoadScopes() if err != nil { return err } return T("scopes.html").Execute(w, map[string]interface{}{ "ctx": ctx, "scopes": scopes, }) return nil }