authorizer/server/server.go

37 lines
1.0 KiB
Go
Raw Normal View History

package main
import (
"context"
2021-07-17 23:18:42 +00:00
"log"
"github.com/gin-gonic/gin"
"github.com/yauthdev/yauth/server/enum"
"github.com/yauthdev/yauth/server/handlers"
"github.com/yauthdev/yauth/server/oauth"
)
func GinContextToContextMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
ctx := context.WithValue(c.Request.Context(), "GinContextKey", c)
c.Request = c.Request.WithContext(ctx)
c.Next()
}
}
2021-07-12 18:22:16 +00:00
func main() {
r := gin.Default()
r.Use(GinContextToContextMiddleware())
r.GET("/", handlers.PlaygroundHandler())
r.POST("/graphql", handlers.GraphqlHandler())
if oauth.OAuthProvider.GoogleConfig != nil {
r.GET("/login/google", handlers.HandleOAuthLogin(enum.GoogleProvider))
r.GET("/callback/google", handlers.HandleOAuthCallback(enum.GoogleProvider))
}
2021-07-17 23:18:42 +00:00
log.Println(oauth.OAuthProvider.GithubConfig)
if oauth.OAuthProvider.GithubConfig != nil {
r.GET("/login/github", handlers.HandleOAuthLogin(enum.GithubProvider))
r.GET("/callback/github", handlers.HandleOAuthCallback(enum.GithubProvider))
}
r.Run()
}