initial commit

This commit is contained in:
Sam 2022-05-02 17:19:37 +02:00
commit 5a75f99720
20 changed files with 2239 additions and 0 deletions

View file

@ -0,0 +1,18 @@
package auth
import (
"os"
"golang.org/x/oauth2"
)
var oauthConfig = oauth2.Config{
ClientID: os.Getenv("DISCORD_CLIENT_ID"),
ClientSecret: os.Getenv("DISCORD_CLIENT_SECRET"),
Endpoint: oauth2.Endpoint{
AuthURL: "https://discord.com/api/oauth2/authorize",
TokenURL: "https://discord.com/api/oauth2/token",
AuthStyle: oauth2.AuthStyleInParams,
},
Scopes: []string{"identify"},
}

View file

@ -0,0 +1,27 @@
package auth
import (
"net/http"
"github.com/go-chi/chi/v5"
"gitlab.com/1f320/pronouns/backend/server"
)
type Server struct {
*server.Server
}
func Mount(srv *server.Server, r chi.Router) {
s := &Server{srv}
_ = s
r.Route("/auth/discord", func(r chi.Router) {
r.Get("/authorize", nil) // generate csrf token, returns URL
r.Get("/callback", nil) // takes code + state, validates it, returns token OR discord signup ticket
r.Get("/signup", nil) // takes discord signup ticket to register account
r.Get("/test", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("hello world!"))
})
})
}