MCPcopy Index your code
hub / github.com/CovenantSQL/CovenantSQL / adminOAuthCallback

Function adminOAuthCallback

cmd/cql-proxy/api/admin_oauth.go:52–100  ·  view source on GitHub ↗
(c *gin.Context)

Source from the content-addressed store, hash-verified

50}
51
52func adminOAuthCallback(c *gin.Context) {
53 r := struct {
54 State string `json:"state" form:"state" binding:"required"`
55 Code string `json:"code" form:"code" binding:"required"`
56 }{}
57
58 if err := c.ShouldBind(&r); err != nil {
59 abortWithError(c, http.StatusBadRequest, err)
60 return
61 }
62
63 authz := getAdminAuth(c)
64 userInfo, err := authz.HandleLogin(c, r.State, r.Code)
65 if err != nil {
66 abortWithError(c, http.StatusForbidden, err)
67 return
68 }
69
70 d, err := model.EnsureDeveloper(model.GetDB(c), userInfo.ID, userInfo.Name, userInfo.Email, userInfo.Extra)
71 if err != nil {
72 _ = c.Error(err)
73 abortWithError(c, http.StatusInternalServerError, ErrUpdateDeveloperAccount)
74 return
75 }
76
77 // save session
78 sessionExpireSeconds := int64(getConfig(c).AdminAuth.OAuthExpires.Seconds())
79 s, err := model.NewSession(model.GetDB(c), sessionExpireSeconds)
80 if err != nil {
81 _ = c.Error(err)
82 abortWithError(c, http.StatusInternalServerError, ErrCreateSessionFailed)
83 return
84 }
85
86 c.Set("session", s)
87
88 s.Set("admin", true)
89 s.Set("developer_id", d.ID)
90 s.Set("github_id", userInfo.ID)
91 s.Set("name", userInfo.Name)
92 s.Set("email", userInfo.Email)
93
94 responseWithData(c, http.StatusOK, gin.H{
95 "token": s.ID,
96 "name": d.Name,
97 "email": d.Email,
98 "extra": d.Extra,
99 })
100}
101
102func adminOAuthLogout(c *gin.Context) {
103 err := model.DeleteSession(model.GetDB(c), getSession(c))

Callers

nothing calls this directly

Calls 10

SetMethod · 0.95
EnsureDeveloperFunction · 0.92
GetDBFunction · 0.92
NewSessionFunction · 0.92
abortWithErrorFunction · 0.85
getAdminAuthFunction · 0.85
getConfigFunction · 0.85
responseWithDataFunction · 0.85
HandleLoginMethod · 0.80
ErrorMethod · 0.80

Tested by

no test coverage detected