Wannabe oauth implementation
This commit is contained in:
44
oauth2server/server/server.go
Normal file
44
oauth2server/server/server.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"local/oauth2/oauth2server/config"
|
||||
"local/router"
|
||||
"local/storage"
|
||||
)
|
||||
|
||||
var wildcard = router.Wildcard
|
||||
|
||||
const (
|
||||
USERS = "users"
|
||||
ACCESS = "access"
|
||||
TOKEN = "token"
|
||||
SALT = "salt"
|
||||
)
|
||||
|
||||
type Server struct {
|
||||
*router.Router
|
||||
store storage.DB
|
||||
}
|
||||
|
||||
func New() *Server {
|
||||
store, err := storage.New(storage.TypeFromString(config.Store), config.StoreAddr, config.StoreUser, config.StorePass)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
purgeIssuedCredentials(store)
|
||||
return &Server{
|
||||
Router: router.New(),
|
||||
store: store,
|
||||
}
|
||||
}
|
||||
|
||||
func purgeIssuedCredentials(store storage.DB) {
|
||||
accesses, _ := store.List([]string{ACCESS})
|
||||
for _, access := range accesses {
|
||||
store.Set(access, nil, ACCESS)
|
||||
}
|
||||
tokens, _ := store.List([]string{TOKEN})
|
||||
for _, token := range tokens {
|
||||
store.Set(token, nil, TOKEN)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user