1
0
mirror of https://github.com/mgerb/go-discord-bot synced 2026-01-11 01:22:48 +00:00

back end done for video archiving

This commit is contained in:
2018-08-20 23:37:58 -05:00
parent e593472c84
commit 5a542e0ffb
16 changed files with 272 additions and 125 deletions

View File

@@ -0,0 +1,61 @@
package routes
import (
"github.com/gin-gonic/gin"
"github.com/mgerb/go-discord-bot/server/webserver/discord"
"github.com/mgerb/go-discord-bot/server/webserver/middleware"
log "github.com/sirupsen/logrus"
)
const cashGuildID = "101198129352691712"
type oauthReq struct {
Code string `json:"code"`
}
// AddOauthRoutes -
func AddOauthRoutes(group *gin.RouterGroup) {
group.POST("/oauth", oauthHandler)
}
func oauthHandler(c *gin.Context) {
var json oauthReq
err := c.ShouldBindJSON(&json)
if err != nil {
log.Error(err)
c.JSON(500, err)
return
}
// get users oauth code
oauth, err := discord.Oauth(json.Code)
if err != nil {
log.Error(err)
c.JSON(500, err)
return
}
// verify and grab user information
user, err := discord.GetUserInfo(oauth.AccessToken)
if err != nil {
log.Error(err)
c.JSON(500, err)
return
}
// generate json web token
token, err := middleware.GetJWT(user)
if err != nil {
log.Error(err)
c.JSON(500, err)
return
}
c.JSON(200, token)
}