Skip to content

Commit

Permalink
add email scope
Browse files Browse the repository at this point in the history
  • Loading branch information
motoki317 committed May 8, 2024
1 parent 13c15f4 commit 4e5889d
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 11 deletions.
37 changes: 28 additions & 9 deletions migration/v35.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,37 @@ func v35() *gormigrate.Migration {
return &gormigrate.Migration{
ID: "35",
Migrate: func(db *gorm.DB) error {
v := v35UserRole{
Name: "profile",
Oauth2Scope: true,
System: true,
Permissions: []v35RolePermission{
{
Role: "profile",
Permission: "get_me",
roles := []v35UserRole{
{
Name: "profile",
Oauth2Scope: true,
System: true,
Permissions: []v35RolePermission{
{
Role: "profile",
Permission: "get_me",
},
},
},
{
Name: "email",
Oauth2Scope: true,
System: true,
Permissions: []v35RolePermission{
{
Role: "profile",
Permission: "get_me",
},
},
},
}
for _, role := range roles {
err := db.Create(&role).Error
if err != nil {
return err
}
}
return db.Create(v).Error
return nil
},
}
}
Expand Down
2 changes: 1 addition & 1 deletion model/oauth2.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type AccessScopes map[AccessScope]struct{}

// SupportedAccessScopes 対応するスコープ一覧を返します
func SupportedAccessScopes() []string {
return []string{"read", "write", "manage_bot", "openid", "profile"}
return []string{"read", "write", "manage_bot", "openid", "profile", "email"}
}

// Value database/sql/driver.Valuer 実装
Expand Down
2 changes: 2 additions & 0 deletions service/oidc/userinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ func (s *Service) GetUserInfo(userID uuid.UUID) (map[string]any, error) {
return map[string]any{
// OIDC standard claims
"name": user.GetName(),
"email": user.GetName() + "+dummy@example.com",
"email_verified": false,
"preferred_username": user.GetName(),
"picture": s.origin + "/api/v3/public/icon/" + user.GetName(),
"updated_at": user.GetUpdatedAt(),
Expand Down
12 changes: 12 additions & 0 deletions service/rbac/role/email.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package role

import (
"github.com/traPtitech/traQ/service/rbac/permission"
)

// Email ユーザー情報読み取り専用ロール (for OIDC)
const Email = "email"

var emailPerms = []permission.Permission{
permission.GetMe,
}
2 changes: 1 addition & 1 deletion service/rbac/role/profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"github.com/traPtitech/traQ/service/rbac/permission"
)

// Profile ユーザー情報読み取り専用ロール
// Profile ユーザー情報読み取り専用ロール (for OIDC)
const Profile = "profile"

var profilePerms = []permission.Permission{
Expand Down
5 changes: 5 additions & 0 deletions service/rbac/role/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ func GetSystemRoles() Roles {
oauth2Scope: true,
permissions: permission.PermissionsFromArray(profilePerms),
},
Email: &systemRole{
name: Email,
oauth2Scope: true,
permissions: permission.PermissionsFromArray(emailPerms),
},
}
}

Expand Down

0 comments on commit 4e5889d

Please sign in to comment.