@@ -24,7 +24,8 @@ import (
24
24
)
25
25
26
26
type issuer struct {
27
- Issuer string
27
+ Issuer string
28
+ Subject string
28
29
}
29
30
30
31
type Oidc struct {
@@ -123,7 +124,8 @@ func (o *Oidc) RegistrationAPI(w http.ResponseWriter, r *http.Request) {
123
124
log .Println (user .Username , clientTunnelIp , "registering with oidc" )
124
125
125
126
value , _ := json .Marshal (issuer {
126
- Issuer : o .provider .Issuer (),
127
+ Issuer : o .provider .Issuer (),
128
+ Subject : "" , // Empty is unconfigured waiting for first login
127
129
})
128
130
129
131
err = data .SetUserMfa (user .Username , string (value ), o .Type ())
@@ -167,7 +169,7 @@ func (o *Oidc) AuthorisationAPI(w http.ResponseWriter, r *http.Request) {
167
169
return
168
170
}
169
171
170
- deviceUsername := info .PreferredUsername
172
+ suppliedUsername := info .PreferredUsername
171
173
172
174
if len (o .details .DeviceUsernameClaim ) != 0 {
173
175
@@ -178,7 +180,7 @@ func (o *Oidc) AuthorisationAPI(w http.ResponseWriter, r *http.Request) {
178
180
return
179
181
}
180
182
181
- deviceUsername = deviceUsernameClaim
183
+ suppliedUsername = deviceUsernameClaim
182
184
183
185
}
184
186
@@ -207,8 +209,26 @@ func (o *Oidc) AuthorisationAPI(w http.ResponseWriter, r *http.Request) {
207
209
return fmt .Errorf ("stored issuer %q did not equal actual issuer: %q" , issuerDetails .Issuer , rp .Issuer ())
208
210
}
209
211
210
- if deviceUsername != username {
211
- log .Printf ("Error logging in user, idP supplied device username (%q) does not equal expected username (%q)" , deviceUsername , username )
212
+ // On first OIDC login this will be unset
213
+ if issuerDetails .Subject == "" {
214
+
215
+ issuerDetails .Subject = info .Subject
216
+
217
+ value , _ := json .Marshal (issuerDetails )
218
+
219
+ err = data .SetUserMfa (user .Username , string (value ), o .Type ())
220
+ if err != nil {
221
+ return fmt .Errorf ("unable to set oidc subject: %s" , err )
222
+ }
223
+ }
224
+
225
+ if issuerDetails .Subject != info .Subject {
226
+ log .Printf ("Error logging in user, idP supplied device username (%q) does not equal expected username (%q)" , suppliedUsername , username )
227
+ return fmt .Errorf ("idp subject %q is not equal to subject %q associated with username %q" , info .Subject , issuerDetails .Subject , username )
228
+ }
229
+
230
+ if suppliedUsername != username {
231
+ log .Printf ("Error logging in user, idP supplied username (%q) does not equal username (%q) associated with device" , suppliedUsername , username )
212
232
return errors .New ("user is not associated with device" )
213
233
}
214
234
0 commit comments