Skip to content

Commit

Permalink
add .well-known proxy endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
BK1031 committed Sep 12, 2024
1 parent f1d03be commit 3a5dbb2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
23 changes: 16 additions & 7 deletions controller/oauth_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,11 @@ func OauthAuthorize(c *gin.Context) {
} else {
prompt = "consent"
}
reponseType := c.Query("response_type")
if reponseType == "" {
reponseType = "code"
}

// Handle Validate Request
if c.Request.Method == "GET" {
c.JSON(http.StatusOK, gin.H{
Expand All @@ -173,20 +178,24 @@ func OauthAuthorize(c *gin.Context) {
})
return
}

// Handle Authorize Request
code, err := service.GenerateAuthorizationCode(clientID, GetRequestUserID(c), scope)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
return
}
go service.CreateLogin(model.UserLogin{
defer service.CreateLogin(model.UserLogin{
UserID: GetRequestUserID(c),
Destination: clientID,
Scope: scope,
IPAddress: c.ClientIP(),
LoginType: "oauth",
})
c.JSON(http.StatusOK, code)
if reponseType == "code" {
code, err := service.GenerateAuthorizationCode(clientID, GetRequestUserID(c), scope)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"message": err.Error()})
return
}
c.JSON(http.StatusOK, code)
return
}
}

func OauthExchange(c *gin.Context) {
Expand Down
4 changes: 2 additions & 2 deletions controller/route_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ func SetupRouter() *gin.Engine {

func InitializeRoutes(router *gin.Engine) {
router.GET("/ping", Ping)
router.GET("/jwks.json", GetJWKS)
router.GET("/openid-configuration", GetOpenIDConfig)
router.GET("/config/jwks.json", GetJWKS)
router.GET("/config/openid-configuration", GetOpenIDConfig)
router.POST("/auth/register", RegisterAccountPassword)
router.POST("/auth/login", LoginAccount)
router.POST("/auth/login/discord", LoginDiscord)
Expand Down
4 changes: 2 additions & 2 deletions model/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ type TokenResponse struct {
}

type AuthClaims struct {
Email string `json:"email"`
Scope string `json:"scope"`
Email string `json:"email,omitempty"`
Scope string `json:"scope,omitempty"`
jwt.RegisteredClaims
}

Expand Down
4 changes: 3 additions & 1 deletion service/auth_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"unicode"

"github.com/golang-jwt/jwt/v4"
"github.com/google/uuid"
"golang.org/x/crypto/bcrypt"
)

Expand Down Expand Up @@ -133,7 +134,8 @@ func GenerateJWT(userID string, email string, scope string, client_id string) (s
Email: email,
Scope: scope,
RegisteredClaims: jwt.RegisteredClaims{
ID: userID,
ID: uuid.NewString(),
Subject: userID,
Issuer: "https://sso.gauchoracing.com/",
Audience: jwt.ClaimStrings{client_id},
IssuedAt: jwt.NewNumericDate(time.Now()),
Expand Down
6 changes: 6 additions & 0 deletions web/netlify.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
status = 200
force = true

[[redirects]]
from = "/.well-known/*"
to = "https://sentinel-api.gauchoracing.com/config/:splat"
status = 200
force = true

[[redirects]]
from = "/*"
to = "/index.html"
Expand Down

0 comments on commit 3a5dbb2

Please sign in to comment.