mirror of
https://github.com/mgerb/go-discord-bot
synced 2026-01-09 16:42:48 +00:00
51 lines
716 B
Go
51 lines
716 B
Go
package handlers
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/mgerb/go-discord-bot/server/webserver/discord"
|
|
log "github.com/sirupsen/logrus"
|
|
)
|
|
|
|
const cashGuildID = "101198129352691712"
|
|
|
|
type oauthReq struct {
|
|
Code string `json:"code"`
|
|
}
|
|
|
|
// Oauth -
|
|
func Oauth(c *gin.Context) {
|
|
|
|
var json oauthReq
|
|
|
|
err := c.ShouldBindJSON(&json)
|
|
|
|
if err != nil {
|
|
log.Error(err)
|
|
c.JSON(500, err)
|
|
return
|
|
}
|
|
|
|
oauth, err := discord.Oauth(json.Code)
|
|
|
|
if err != nil {
|
|
log.Error(err)
|
|
c.JSON(500, err)
|
|
return
|
|
}
|
|
|
|
user, err := discord.GetUserInfo(oauth.AccessToken)
|
|
|
|
if err != nil {
|
|
log.Error(err)
|
|
c.JSON(500, err)
|
|
return
|
|
}
|
|
|
|
// TODO: generate jwt for user
|
|
fmt.Println(user)
|
|
|
|
c.JSON(200, oauth)
|
|
}
|