Skip to content

Commit 8c81a2b

Browse files
committed
assert phone/email verified when either is set
1 parent 868a2b9 commit 8c81a2b

8 files changed

Lines changed: 91 additions & 98 deletions

File tree

internal/assets/migrations/000008_oidc_userinfo_profile.up.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,4 @@ ALTER TABLE "oidc_userinfo" ADD COLUMN "birthdate" TEXT NOT NULL
1010
ALTER TABLE "oidc_userinfo" ADD COLUMN "zoneinfo" TEXT NOT NULL DEFAULT "";
1111
ALTER TABLE "oidc_userinfo" ADD COLUMN "locale" TEXT NOT NULL DEFAULT "";
1212
ALTER TABLE "oidc_userinfo" ADD COLUMN "phone_number" TEXT NOT NULL DEFAULT "";
13-
ALTER TABLE "oidc_userinfo" ADD COLUMN "phone_number_verified" INTEGER NOT NULL DEFAULT 0;
1413
ALTER TABLE "oidc_userinfo" ADD COLUMN "address" TEXT NOT NULL DEFAULT "{}";

internal/config/config.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,21 @@ type AuthConfig struct {
126126
}
127127

128128
type UserAttributes struct {
129-
Name string `description:"Full name of the user." yaml:"name"`
130-
GivenName string `description:"Given (first) name of the user." yaml:"givenName"`
131-
FamilyName string `description:"Family (last) name of the user." yaml:"familyName"`
132-
MiddleName string `description:"Middle name of the user." yaml:"middleName"`
133-
Nickname string `description:"Nickname of the user." yaml:"nickname"`
134-
Profile string `description:"URL of the user's profile page." yaml:"profile"`
135-
Picture string `description:"URL of the user's profile picture." yaml:"picture"`
136-
Website string `description:"URL of the user's website." yaml:"website"`
137-
Email string `description:"Email address of the user." yaml:"email"`
138-
Gender string `description:"Gender of the user." yaml:"gender"`
139-
Birthdate string `description:"Birthdate of the user (YYYY-MM-DD)." yaml:"birthdate"`
140-
Zoneinfo string `description:"Time zone of the user (e.g. Europe/Athens)." yaml:"zoneinfo"`
141-
Locale string `description:"Locale of the user (e.g. en-US)." yaml:"locale"`
142-
PhoneNumber string `description:"Phone number of the user." yaml:"phoneNumber"`
143-
PhoneNumberVerified bool `description:"Whether the phone number has been verified." yaml:"phoneNumberVerified"`
144-
Address AddressClaim `description:"Address of the user." yaml:"address"`
129+
Name string `description:"Full name of the user." yaml:"name"`
130+
GivenName string `description:"Given (first) name of the user." yaml:"givenName"`
131+
FamilyName string `description:"Family (last) name of the user." yaml:"familyName"`
132+
MiddleName string `description:"Middle name of the user." yaml:"middleName"`
133+
Nickname string `description:"Nickname of the user." yaml:"nickname"`
134+
Profile string `description:"URL of the user's profile page." yaml:"profile"`
135+
Picture string `description:"URL of the user's profile picture." yaml:"picture"`
136+
Website string `description:"URL of the user's website." yaml:"website"`
137+
Email string `description:"Email address of the user." yaml:"email"`
138+
Gender string `description:"Gender of the user." yaml:"gender"`
139+
Birthdate string `description:"Birthdate of the user (YYYY-MM-DD)." yaml:"birthdate"`
140+
Zoneinfo string `description:"Time zone of the user (e.g. Europe/Athens)." yaml:"zoneinfo"`
141+
Locale string `description:"Locale of the user (e.g. en-US)." yaml:"locale"`
142+
PhoneNumber string `description:"Phone number of the user." yaml:"phoneNumber"`
143+
Address AddressClaim `description:"Address of the user." yaml:"address"`
145144
}
146145

147146
type AddressClaim struct {

internal/repository/models.go

Lines changed: 19 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/repository/oidc_queries.sql.go

Lines changed: 22 additions & 27 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/service/oidc_service.go

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,7 @@ func (service *OIDCService) StoreUserinfo(c *gin.Context, sub string, userContex
390390
Zoneinfo: userContext.Attributes.Zoneinfo,
391391
Locale: userContext.Attributes.Locale,
392392
PhoneNumber: userContext.Attributes.PhoneNumber,
393-
PhoneNumberVerified: func() int64 {
394-
if userContext.Attributes.PhoneNumberVerified {
395-
return 1
396-
}
397-
return 0
398-
}(),
399-
Address: string(addressJSON),
393+
Address: string(addressJSON),
400394
}
401395

402396
// Tinyauth will pass through the groups it got from an LDAP or an OIDC server
@@ -692,8 +686,7 @@ func (service *OIDCService) CompileUserinfo(user repository.OidcUserinfo, scope
692686

693687
if slices.Contains(scopes, "email") {
694688
userInfo.Email = user.Email
695-
// We can set this as a configuration option in the future but for now it's a good idea to assume it's true
696-
userInfo.EmailVerified = true
689+
userInfo.EmailVerified = user.Email != ""
697690
}
698691

699692
if slices.Contains(scopes, "groups") {
@@ -706,7 +699,7 @@ func (service *OIDCService) CompileUserinfo(user repository.OidcUserinfo, scope
706699

707700
if slices.Contains(scopes, "phone") {
708701
userInfo.PhoneNumber = user.PhoneNumber
709-
verified := user.PhoneNumberVerified != 0
702+
verified := user.PhoneNumber != ""
710703
userInfo.PhoneNumberVerified = &verified
711704
}
712705

internal/service/oidc_service_test.go

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,25 @@ func newTestUser() repository.OidcUserinfo {
2424
addrJSON, _ := json.Marshal(addr)
2525

2626
return repository.OidcUserinfo{
27-
Sub: "test-sub",
28-
Name: "Test User",
29-
PreferredUsername: "testuser",
30-
Email: "test@example.com",
31-
Groups: "admins,users",
32-
UpdatedAt: 1234567890,
33-
GivenName: "Test",
34-
FamilyName: "User",
35-
MiddleName: "M",
36-
Nickname: "testy",
37-
Profile: "https://example.com/testuser",
38-
Picture: "https://example.com/testuser.jpg",
39-
Website: "https://testuser.example.com",
40-
Gender: "male",
41-
Birthdate: "1990-01-01",
42-
Zoneinfo: "America/Chicago",
43-
Locale: "en-US",
44-
PhoneNumber: "+15555550100",
45-
PhoneNumberVerified: 1,
46-
Address: string(addrJSON),
27+
Sub: "test-sub",
28+
Name: "Test User",
29+
PreferredUsername: "testuser",
30+
Email: "test@example.com",
31+
Groups: "admins,users",
32+
UpdatedAt: 1234567890,
33+
GivenName: "Test",
34+
FamilyName: "User",
35+
MiddleName: "M",
36+
Nickname: "testy",
37+
Profile: "https://example.com/testuser",
38+
Picture: "https://example.com/testuser.jpg",
39+
Website: "https://testuser.example.com",
40+
Gender: "male",
41+
Birthdate: "1990-01-01",
42+
Zoneinfo: "America/Chicago",
43+
Locale: "en-US",
44+
PhoneNumber: "+15555550100",
45+
Address: string(addrJSON),
4746
}
4847
}
4948

@@ -110,6 +109,17 @@ func TestCompileUserinfo_EmailScope(t *testing.T) {
110109
assert.Empty(t, info.Name) // profile not requested
111110
}
112111

112+
func TestCompileUserinfo_EmailScope_Unverified(t *testing.T) {
113+
svc := newOIDCService(t)
114+
user := newTestUser()
115+
user.Email = ""
116+
117+
info := svc.CompileUserinfo(user, "openid,email")
118+
119+
assert.Empty(t, info.Email)
120+
assert.False(t, info.EmailVerified)
121+
}
122+
113123
func TestCompileUserinfo_PhoneScope(t *testing.T) {
114124
svc := newOIDCService(t)
115125
user := newTestUser()
@@ -124,7 +134,7 @@ func TestCompileUserinfo_PhoneScope(t *testing.T) {
124134
func TestCompileUserinfo_PhoneScope_Unverified(t *testing.T) {
125135
svc := newOIDCService(t)
126136
user := newTestUser()
127-
user.PhoneNumberVerified = 0
137+
user.PhoneNumber = ""
128138

129139
info := svc.CompileUserinfo(user, "openid,phone")
130140

sql/oidc_queries.sql

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,9 @@ INSERT INTO "oidc_userinfo" (
103103
"zoneinfo",
104104
"locale",
105105
"phone_number",
106-
"phone_number_verified",
107106
"address"
108107
) VALUES (
109-
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
108+
?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?
110109
)
111110
RETURNING *;
112111

sql/oidc_schemas.sql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,5 @@ CREATE TABLE IF NOT EXISTS "oidc_userinfo" (
3939
"zoneinfo" TEXT NOT NULL,
4040
"locale" TEXT NOT NULL,
4141
"phone_number" TEXT NOT NULL,
42-
"phone_number_verified" INTEGER NOT NULL,
4342
"address" TEXT NOT NULL
4443
);

0 commit comments

Comments
 (0)