oauth2/oauth2server/server/server.go

80 lines
1.8 KiB
Go
Executable File

package server
import (
"fmt"
"gogs.inhome.blapointe.com/local/oauth2/oauth2server/config"
"gogs.inhome.blapointe.com/local/router"
"gogs.inhome.blapointe.com/local/storage"
"golang.org/x/time/rate"
)
var wildcard = router.Wildcard
const (
USERS = "users"
ACCESS = "access"
TOKEN = "token"
SALT = "salt"
)
type Server struct {
*router.Router
store storage.DB
limiter *rate.Limiter
}
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,
limiter: rate.NewLimiter(1, 3),
}
}
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)
}
}
func wrapBody(title, body string) string {
return fmt.Sprintf(`
<html>
<head>
<meta name="viewport" content="width=device-width, user-scalable=no">
<title>%s</title>
<style>body{
max-width: 960px;
overflow: hidden;
filter:invert(80%%);
background-color: #222;
font-size: 5em;
zoom: 1.5;
-moz-transform: scale(1.5);
-moz-transform-origin: 0 0;
-o-transform: scale(1.5);
-o-transform-origin: 0 0;
-webkit-transform: scale(1.5);
-webkit-transform-origin: 0 0;
transform: scale(1.5);
transform-origin: 0 0;
}</style>
</head>
<body>
%s
</body>
</html>
`, title, body)
}