MCPcopy Create free account
hub / github.com/Mnexa-AI/e2a / CreateAuthorizeCodeSession

Method CreateAuthorizeCodeSession

internal/oauth/storage.go:217–248  ·  view source on GitHub ↗
(ctx context.Context, code string, request fosite.Requester)

Source from the content-addressed store, hash-verified

215}
216
217func (s *Storage) CreateAuthorizeCodeSession(ctx context.Context, code string, request fosite.Requester) error {
218 raw, err := marshalRequest(request)
219 if err != nil {
220 return err
221 }
222 sess, _ := request.GetSession().(*Session)
223 userID := ""
224 if sess != nil {
225 userID = sess.UserID
226 }
227 // Honor fosite's session-supplied expiry — it reflects the
228 // AuthorizeCodeLifespan from the compose config. Falling back to a
229 // hardcoded value here would let the retention reaper truncate
230 // codes fosite still considers valid (different lifetimes on each
231 // side of the HMAC). Default is fosite's 15min if the caller
232 // somehow didn't set one.
233 expiresAt := request.GetRequestedAt().Add(15 * time.Minute)
234 if sess != nil {
235 if t := sess.GetExpiresAt(fosite.AuthorizeCode); !t.IsZero() {
236 expiresAt = t
237 }
238 }
239 _, err = s.db(ctx).Exec(ctx, `
240 INSERT INTO oauth_auth_codes
241 (signature, request_id, client_id, user_id, request,
242 requested_at, expires_at, active)
243 VALUES ($1, $2, $3, $4, $5, $6, $7, TRUE)
244 `, code, request.GetID(), request.GetClient().GetID(), userID,
245 raw, request.GetRequestedAt(), expiresAt,
246 )
247 return err
248}
249
250func (s *Storage) GetAuthorizeCodeSession(ctx context.Context, code string, session fosite.Session) (fosite.Requester, error) {
251 var raw []byte

Calls 6

dbMethod · 0.95
marshalRequestFunction · 0.85
GetExpiresAtMethod · 0.80
GetIDMethod · 0.80
GetClientMethod · 0.80
ExecMethod · 0.65