2024-08-17 21:57:14 +02:00
|
|
|
package controller
|
2024-08-12 11:00:25 +02:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"net/http"
|
2025-02-05 18:08:01 +01:00
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
|
"github.com/pocket-id/pocket-id/backend/internal/common"
|
|
|
|
|
"github.com/pocket-id/pocket-id/backend/internal/service"
|
2024-08-12 11:00:25 +02:00
|
|
|
)
|
|
|
|
|
|
2024-08-17 21:57:14 +02:00
|
|
|
func NewWellKnownController(group *gin.RouterGroup, jwtService *service.JwtService) {
|
|
|
|
|
wkc := &WellKnownController{jwtService: jwtService}
|
|
|
|
|
group.GET("/.well-known/jwks.json", wkc.jwksHandler)
|
|
|
|
|
group.GET("/.well-known/openid-configuration", wkc.openIDConfigurationHandler)
|
2024-08-12 11:00:25 +02:00
|
|
|
}
|
|
|
|
|
|
2024-08-17 21:57:14 +02:00
|
|
|
type WellKnownController struct {
|
|
|
|
|
jwtService *service.JwtService
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (wkc *WellKnownController) jwksHandler(c *gin.Context) {
|
|
|
|
|
jwk, err := wkc.jwtService.GetJWK()
|
2024-08-12 11:00:25 +02:00
|
|
|
if err != nil {
|
2024-10-28 18:11:54 +01:00
|
|
|
c.Error(err)
|
2024-08-12 11:00:25 +02:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
c.JSON(http.StatusOK, gin.H{"keys": []interface{}{jwk}})
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-17 21:57:14 +02:00
|
|
|
func (wkc *WellKnownController) openIDConfigurationHandler(c *gin.Context) {
|
2024-08-12 11:00:25 +02:00
|
|
|
appUrl := common.EnvConfig.AppURL
|
|
|
|
|
config := map[string]interface{}{
|
|
|
|
|
"issuer": appUrl,
|
|
|
|
|
"authorization_endpoint": appUrl + "/authorize",
|
|
|
|
|
"token_endpoint": appUrl + "/api/oidc/token",
|
2024-08-19 18:48:18 +02:00
|
|
|
"userinfo_endpoint": appUrl + "/api/oidc/userinfo",
|
2025-02-14 17:09:27 +01:00
|
|
|
"end_session_endpoint": appUrl + "/api/oidc/end-session",
|
2024-08-12 11:00:25 +02:00
|
|
|
"jwks_uri": appUrl + "/.well-known/jwks.json",
|
|
|
|
|
"scopes_supported": []string{"openid", "profile", "email"},
|
2025-02-19 14:28:45 +01:00
|
|
|
"claims_supported": []string{"sub", "given_name", "family_name", "name", "email", "email_verified", "preferred_username", "picture"},
|
2024-08-12 11:00:25 +02:00
|
|
|
"response_types_supported": []string{"code", "id_token"},
|
|
|
|
|
"subject_types_supported": []string{"public"},
|
|
|
|
|
"id_token_signing_alg_values_supported": []string{"RS256"},
|
|
|
|
|
}
|
|
|
|
|
c.JSON(http.StatusOK, config)
|
|
|
|
|
}
|