Skip to content

Commit

Permalink
feat oauth2
Browse files Browse the repository at this point in the history
  • Loading branch information
a3510377 committed May 8, 2024
1 parent ed5ae4f commit 591234d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
36 changes: 36 additions & 0 deletions server/api/oauth2.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package api

import (
"net/http"

"github.com/gin-gonic/gin"
"golang.org/x/oauth2"
)

var Endpoint = oauth2.Endpoint{
AuthURL: "https://discord.com/api/oauth2/authorize",
TokenURL: "https://discord.com/api/oauth2/token",
AuthStyle: oauth2.AuthStyleInParams,
}

var conf = &oauth2.Config{
Endpoint: Endpoint,
Scopes: []string{},
RedirectURL: "http://localhost:3000/auth/callback",
ClientID: "id",
ClientSecret: "secret",
}

func RegisterOauth2(router *gin.RouterGroup) {
discord := router.Group("/discord")
discord.GET("/redirect", HandlerOAuth2Redirect)
discord.GET("/callback", HandlerOAuth2Callback)
}

func HandlerOAuth2Redirect(ctx *gin.Context) {
state := "testing"
ctx.Redirect(http.StatusTemporaryRedirect, conf.AuthCodeURL(state))
}

func HandlerOAuth2Callback(ctx *gin.Context) {
}
6 changes: 5 additions & 1 deletion server/api/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package api

import "github.com/gin-gonic/gin"
import (
"github.com/gin-gonic/gin"
)

func RegisterRoutes(router *gin.Engine) {
api := router.Group("/api")
Expand All @@ -9,4 +11,6 @@ func RegisterRoutes(router *gin.Engine) {
})

api.GET("/members", HandlerGetWhitelistMembers)

RegisterOauth2(api.Group("/oauth2"))
}
1 change: 1 addition & 0 deletions server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/golang-jwt/jwt/v5 v5.2.1
github.com/mattn/go-colorable v0.1.13
github.com/sirupsen/logrus v1.9.3
golang.org/x/oauth2 v0.20.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/apimachinery v0.30.0
)
Expand Down
2 changes: 2 additions & 0 deletions server/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30=
golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M=
golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w=
golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8=
golang.org/x/oauth2 v0.20.0 h1:4mQdhULixXKP1rwYBW0vAijoXnkTG0BLCDRzfe1idMo=
golang.org/x/oauth2 v0.20.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down

0 comments on commit 591234d

Please sign in to comment.