Skip to content

Commit 986ac88

Browse files
committed
2 parents b159f44 + 43487d4 commit 986ac88

12 files changed

Lines changed: 21 additions & 13 deletions
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "sessions" DROP COLUMN "oauth_sub";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALTER TABLE "sessions" ADD COLUMN "oauth_sub" TEXT;

internal/config/config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ const DefaultNamePrefix = "TINYAUTH_"
7979
// OAuth/OIDC config
8080

8181
type Claims struct {
82+
Sub string `json:"sub"`
8283
Name string `json:"name"`
8384
Email string `json:"email"`
8485
PreferredUsername string `json:"preferred_username"`
@@ -125,6 +126,7 @@ type SessionCookie struct {
125126
TotpPending bool
126127
OAuthGroups string
127128
OAuthName string
129+
OAuthSub string
128130
}
129131

130132
type UserContext struct {
@@ -138,6 +140,7 @@ type UserContext struct {
138140
OAuthGroups string
139141
TotpEnabled bool
140142
OAuthName string
143+
OAuthSub string
141144
}
142145

143146
// API responses and queries

internal/controller/context_controller.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ type UserContextResponse struct {
2121
OAuth bool `json:"oauth"`
2222
TotpPending bool `json:"totpPending"`
2323
OAuthName string `json:"oauthName"`
24+
OAuthSub string `json:"oauthSub"`
2425
}
2526

2627
type AppContextResponse struct {
@@ -89,6 +90,7 @@ func (controller *ContextController) userContextHandler(c *gin.Context) {
8990
OAuth: context.OAuth,
9091
TotpPending: context.TotpPending,
9192
OAuthName: context.OAuthName,
93+
OAuthSub: context.OAuthSub,
9294
}
9395

9496
if err != nil {

internal/controller/context_controller_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ var userContext = config.UserContext{
4444
TotpPending: false,
4545
OAuthGroups: "",
4646
TotpEnabled: false,
47+
OAuthSub: "",
4748
}
4849

4950
func setupContextController(middlewares *[]gin.HandlerFunc) (*gin.Engine, *httptest.ResponseRecorder) {

internal/controller/oauth_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ func (controller *OAuthController) oauthCallbackHandler(c *gin.Context) {
197197
Provider: req.Provider,
198198
OAuthGroups: utils.CoalesceToString(user.Groups),
199199
OAuthName: service.GetName(),
200+
OAuthSub: user.Sub,
200201
}
201202

202203
log.Trace().Interface("session_cookie", sessionCookie).Msg("Creating session cookie")

internal/controller/proxy_controller.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ func (controller *ProxyController) proxyHandler(c *gin.Context) {
239239
c.Header("Remote-Name", utils.SanitizeHeader(userContext.Name))
240240
c.Header("Remote-Email", utils.SanitizeHeader(userContext.Email))
241241
c.Header("Remote-Groups", utils.SanitizeHeader(userContext.OAuthGroups))
242+
c.Header("Remote-Sub", utils.SanitizeHeader(userContext.OAuthSub))
242243

243244
controller.setHeaders(c, acls)
244245

internal/middleware/context_middleware.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ func (m *ContextMiddleware) Middleware() gin.HandlerFunc {
9999
Provider: cookie.Provider,
100100
OAuthGroups: cookie.OAuthGroups,
101101
OAuthName: cookie.OAuthName,
102+
OAuthSub: cookie.OAuthSub,
102103
IsLoggedIn: true,
103104
OAuth: true,
104105
})

internal/model/session_model.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ type Session struct {
1010
OAuthGroups string `gorm:"column:oauth_groups"`
1111
Expiry int64 `gorm:"column:expiry"`
1212
OAuthName string `gorm:"column:oauth_name"`
13+
OAuthSub string `gorm:"column:oauth_sub"`
1314
}

internal/service/auth_service.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ func (auth *AuthService) CreateSessionCookie(c *gin.Context, data *config.Sessio
213213
OAuthGroups: data.OAuthGroups,
214214
Expiry: time.Now().Add(time.Duration(expiry) * time.Second).Unix(),
215215
OAuthName: data.OAuthName,
216+
OAuthSub: data.OAuthSub,
216217
}
217218

218219
err = gorm.G[model.Session](auth.database).Create(c, &session)
@@ -314,6 +315,7 @@ func (auth *AuthService) GetSessionCookie(c *gin.Context) (config.SessionCookie,
314315
TotpPending: session.TOTPPending,
315316
OAuthGroups: session.OAuthGroups,
316317
OAuthName: session.OAuthName,
318+
OAuthSub: session.OAuthSub,
317319
}, nil
318320
}
319321

0 commit comments

Comments
 (0)