| 215 | } |
| 216 | |
| 217 | func (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 | |
| 250 | func (s *Storage) GetAuthorizeCodeSession(ctx context.Context, code string, session fosite.Session) (fosite.Requester, error) { |
| 251 | var raw []byte |