auth.go 1.2 KB

123456789101112131415161718192021222324252627
  1. package auth
  2. import (
  3. "time"
  4. )
  5. const (
  6. // The key name used to store user id in the context
  7. // user id is extracted from the jwt token subject field.
  8. UserIDContextKey = "user-id"
  9. // issuer is the issuer of the jwt token.
  10. Issuer = "memos"
  11. // Signing key section. For now, this is only used for signing, not for verifying since we only
  12. // have 1 version. But it will be used to maintain backward compatibility if we change the signing mechanism.
  13. KeyID = "v1"
  14. // AccessTokenAudienceName is the audience name of the access token.
  15. AccessTokenAudienceName = "user.access-token"
  16. AccessTokenDuration = 7 * 24 * time.Hour
  17. // CookieExpDuration expires slightly earlier than the jwt expiration. Client would be logged out if the user
  18. // cookie expires, thus the client would always logout first before attempting to make a request with the expired jwt.
  19. // Suppose we have a valid refresh token, we will refresh the token in cases:
  20. // 1. The access token has already expired, we refresh the token so that the ongoing request can pass through.
  21. CookieExpDuration = AccessTokenDuration - 1*time.Minute
  22. // AccessTokenCookieName is the cookie name of access token.
  23. AccessTokenCookieName = "memos.access-token"
  24. )