mirror of
https://github.com/1f349/violet.git
synced 2024-11-23 11:51:37 +00:00
31 lines
594 B
Go
31 lines
594 B
Go
package fake
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"crypto/rsa"
|
|
"github.com/1f349/mjwt"
|
|
"github.com/1f349/mjwt/auth"
|
|
"github.com/1f349/mjwt/claims"
|
|
"time"
|
|
)
|
|
|
|
var SnakeOilProv = GenSnakeOilProv()
|
|
|
|
func GenSnakeOilProv() mjwt.Signer {
|
|
key, err := rsa.GenerateKey(rand.Reader, 1024)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return mjwt.NewMJwtSigner("violet.test", key)
|
|
}
|
|
|
|
func GenSnakeOilKey(perm string) string {
|
|
p := claims.NewPermStorage()
|
|
p.Set(perm)
|
|
val, err := SnakeOilProv.GenerateJwt("abc", "abc", nil, 5*time.Minute, auth.AccessTokenClaims{Perms: p})
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return val
|
|
}
|