Add oauth2 like auth service
All checks were successful
Build Backend (NixCN CMS) TeamCity build finished
Build Frontend (NixCN CMS) TeamCity build finished

Signed-off-by: Asai Neko <sugar@sne.moe>
This commit is contained in:
2026-01-02 15:57:42 +08:00
parent 62da1e096e
commit a98ab26fa4
12 changed files with 292 additions and 83 deletions

View File

@@ -25,29 +25,29 @@ func NewAuthCode(email string) (string, error) {
return "", err
}
token := base64.RawURLEncoding.EncodeToString(b)
code := base64.RawURLEncoding.EncodeToString(b)
store.Store(token, Token{
store.Store(code, Token{
Email: email,
ExpiresAt: time.Now().Add(viper.GetDuration("ttl.magic_link_ttl")),
})
return token, nil
return code, nil
}
// Verify magic token
func VerifyAuthCode(token string) (string, bool) {
val, ok := store.Load(token)
func VerifyAuthCode(code string) (string, bool) {
val, ok := store.Load(code)
if !ok {
return "", false
}
t := val.(Token)
if time.Now().After(t.ExpiresAt) {
store.Delete(token)
store.Delete(code)
return "", false
}
store.Delete(token)
store.Delete(code)
return t.Email, true
}