Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
eb33a604
Commit
eb33a604
authored
Apr 24, 2025
by
johnnyjoy
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: support mapping avatar url from oauth2
parent
e4191640
Changes
11
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
113 additions
and
256 deletions
+113
-256
idp.go
plugin/idp/idp.go
+1
-0
oauth2.go
plugin/idp/oauth2/oauth2.go
+5
-0
idp_service.proto
proto/api/v1/idp_service.proto
+1
-0
buf.gen.yaml
proto/buf.gen.yaml
+0
-1
idp_service.pb.go
proto/gen/api/v1/idp_service.pb.go
+12
-2
apidocs.swagger.yaml
proto/gen/apidocs.swagger.yaml
+44
-127
idp.pb.go
proto/gen/store/idp.pb.go
+12
-2
idp.proto
proto/store/idp.proto
+1
-0
auth_service.go
server/router/api/v1/auth_service.go
+4
-3
idp_service.ts
web/src/types/proto/api/v1/idp_service.ts
+14
-1
descriptor.ts
web/src/types/proto/google/protobuf/descriptor.ts
+19
-120
No files found.
plugin/idp/idp.go
View file @
eb33a604
...
@@ -4,4 +4,5 @@ type IdentityProviderUserInfo struct {
...
@@ -4,4 +4,5 @@ type IdentityProviderUserInfo struct {
Identifier
string
Identifier
string
DisplayName
string
DisplayName
string
Email
string
Email
string
AvatarURL
string
}
}
plugin/idp/oauth2/oauth2.go
View file @
eb33a604
...
@@ -113,5 +113,10 @@ func (p *IdentityProvider) UserInfo(token string) (*idp.IdentityProviderUserInfo
...
@@ -113,5 +113,10 @@ func (p *IdentityProvider) UserInfo(token string) (*idp.IdentityProviderUserInfo
userInfo
.
Email
=
v
userInfo
.
Email
=
v
}
}
}
}
if
p
.
config
.
FieldMapping
.
AvatarUrl
!=
""
{
if
v
,
ok
:=
claims
[
p
.
config
.
FieldMapping
.
AvatarUrl
]
.
(
string
);
ok
{
userInfo
.
AvatarURL
=
v
}
}
return
userInfo
,
nil
return
userInfo
,
nil
}
}
proto/api/v1/idp_service.proto
View file @
eb33a604
...
@@ -69,6 +69,7 @@ message FieldMapping {
...
@@ -69,6 +69,7 @@ message FieldMapping {
string
identifier
=
1
;
string
identifier
=
1
;
string
display_name
=
2
;
string
display_name
=
2
;
string
email
=
3
;
string
email
=
3
;
string
avatar_url
=
4
;
}
}
message
OAuth2Config
{
message
OAuth2Config
{
...
...
proto/buf.gen.yaml
View file @
eb33a604
version
:
v2
version
:
v2
clean
:
true
managed
:
managed
:
enabled
:
true
enabled
:
true
disable
:
disable
:
...
...
proto/gen/api/v1/idp_service.pb.go
View file @
eb33a604
...
@@ -219,6 +219,7 @@ type FieldMapping struct {
...
@@ -219,6 +219,7 @@ type FieldMapping struct {
Identifier
string
`protobuf:"bytes,1,opt,name=identifier,proto3" json:"identifier,omitempty"`
Identifier
string
`protobuf:"bytes,1,opt,name=identifier,proto3" json:"identifier,omitempty"`
DisplayName
string
`protobuf:"bytes,2,opt,name=display_name,json=displayName,proto3" json:"display_name,omitempty"`
DisplayName
string
`protobuf:"bytes,2,opt,name=display_name,json=displayName,proto3" json:"display_name,omitempty"`
Email
string
`protobuf:"bytes,3,opt,name=email,proto3" json:"email,omitempty"`
Email
string
`protobuf:"bytes,3,opt,name=email,proto3" json:"email,omitempty"`
AvatarUrl
string
`protobuf:"bytes,4,opt,name=avatar_url,json=avatarUrl,proto3" json:"avatar_url,omitempty"`
unknownFields
protoimpl
.
UnknownFields
unknownFields
protoimpl
.
UnknownFields
sizeCache
protoimpl
.
SizeCache
sizeCache
protoimpl
.
SizeCache
}
}
...
@@ -274,6 +275,13 @@ func (x *FieldMapping) GetEmail() string {
...
@@ -274,6 +275,13 @@ func (x *FieldMapping) GetEmail() string {
return
""
return
""
}
}
func
(
x
*
FieldMapping
)
GetAvatarUrl
()
string
{
if
x
!=
nil
{
return
x
.
AvatarUrl
}
return
""
}
type
OAuth2Config
struct
{
type
OAuth2Config
struct
{
state
protoimpl
.
MessageState
`protogen:"open.v1"`
state
protoimpl
.
MessageState
`protogen:"open.v1"`
ClientId
string
`protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"`
ClientId
string
`protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"`
...
@@ -653,13 +661,15 @@ const file_api_v1_idp_service_proto_rawDesc = "" +
...
@@ -653,13 +661,15 @@ const file_api_v1_idp_service_proto_rawDesc = "" +
"
\x06
OAUTH2
\x10\x01\"
e
\n
"
+
"
\x06
OAUTH2
\x10\x01\"
e
\n
"
+
"
\x16
IdentityProviderConfig
\x12
A
\n
"
+
"
\x16
IdentityProviderConfig
\x12
A
\n
"
+
"
\r
oauth2_config
\x18\x01
\x01
(
\v
2
\x1a
.memos.api.v1.OAuth2ConfigH
\x00
R
\f
oauth2ConfigB
\b\n
"
+
"
\r
oauth2_config
\x18\x01
\x01
(
\v
2
\x1a
.memos.api.v1.OAuth2ConfigH
\x00
R
\f
oauth2ConfigB
\b\n
"
+
"
\x06
config
\"
g
\n
"
+
"
\x06
config
\"
\x86\x01
\n
"
+
"
\f
FieldMapping
\x12\x1e\n
"
+
"
\f
FieldMapping
\x12\x1e\n
"
+
"
\n
"
+
"
\n
"
+
"identifier
\x18\x01
\x01
(
\t
R
\n
"
+
"identifier
\x18\x01
\x01
(
\t
R
\n
"
+
"identifier
\x12
!
\n
"
+
"identifier
\x12
!
\n
"
+
"
\f
display_name
\x18\x02
\x01
(
\t
R
\v
displayName
\x12\x14\n
"
+
"
\f
display_name
\x18\x02
\x01
(
\t
R
\v
displayName
\x12\x14\n
"
+
"
\x05
email
\x18\x03
\x01
(
\t
R
\x05
email
\"\x85\x02\n
"
+
"
\x05
email
\x18\x03
\x01
(
\t
R
\x05
email
\x12\x1d\n
"
+
"
\n
"
+
"avatar_url
\x18\x04
\x01
(
\t
R
\t
avatarUrl
\"\x85\x02\n
"
+
"
\f
OAuth2Config
\x12\x1b\n
"
+
"
\f
OAuth2Config
\x12\x1b\n
"
+
"
\t
client_id
\x18\x01
\x01
(
\t
R
\b
clientId
\x12
#
\n
"
+
"
\t
client_id
\x18\x01
\x01
(
\t
R
\b
clientId
\x12
#
\n
"
+
"
\r
client_secret
\x18\x02
\x01
(
\t
R
\f
clientSecret
\x12\x19\n
"
+
"
\r
client_secret
\x18\x02
\x01
(
\t
R
\f
clientSecret
\x12\x19\n
"
+
...
...
proto/gen/apidocs.swagger.yaml
View file @
eb33a604
This diff is collapsed.
Click to expand it.
proto/gen/store/idp.pb.go
View file @
eb33a604
...
@@ -214,6 +214,7 @@ type FieldMapping struct {
...
@@ -214,6 +214,7 @@ type FieldMapping struct {
Identifier
string
`protobuf:"bytes,1,opt,name=identifier,proto3" json:"identifier,omitempty"`
Identifier
string
`protobuf:"bytes,1,opt,name=identifier,proto3" json:"identifier,omitempty"`
DisplayName
string
`protobuf:"bytes,2,opt,name=display_name,json=displayName,proto3" json:"display_name,omitempty"`
DisplayName
string
`protobuf:"bytes,2,opt,name=display_name,json=displayName,proto3" json:"display_name,omitempty"`
Email
string
`protobuf:"bytes,3,opt,name=email,proto3" json:"email,omitempty"`
Email
string
`protobuf:"bytes,3,opt,name=email,proto3" json:"email,omitempty"`
AvatarUrl
string
`protobuf:"bytes,4,opt,name=avatar_url,json=avatarUrl,proto3" json:"avatar_url,omitempty"`
unknownFields
protoimpl
.
UnknownFields
unknownFields
protoimpl
.
UnknownFields
sizeCache
protoimpl
.
SizeCache
sizeCache
protoimpl
.
SizeCache
}
}
...
@@ -269,6 +270,13 @@ func (x *FieldMapping) GetEmail() string {
...
@@ -269,6 +270,13 @@ func (x *FieldMapping) GetEmail() string {
return
""
return
""
}
}
func
(
x
*
FieldMapping
)
GetAvatarUrl
()
string
{
if
x
!=
nil
{
return
x
.
AvatarUrl
}
return
""
}
type
OAuth2Config
struct
{
type
OAuth2Config
struct
{
state
protoimpl
.
MessageState
`protogen:"open.v1"`
state
protoimpl
.
MessageState
`protogen:"open.v1"`
ClientId
string
`protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"`
ClientId
string
`protobuf:"bytes,1,opt,name=client_id,json=clientId,proto3" json:"client_id,omitempty"`
...
@@ -378,13 +386,15 @@ const file_store_idp_proto_rawDesc = "" +
...
@@ -378,13 +386,15 @@ const file_store_idp_proto_rawDesc = "" +
"
\x06
OAUTH2
\x10\x01\"
d
\n
"
+
"
\x06
OAUTH2
\x10\x01\"
d
\n
"
+
"
\x16
IdentityProviderConfig
\x12
@
\n
"
+
"
\x16
IdentityProviderConfig
\x12
@
\n
"
+
"
\r
oauth2_config
\x18\x01
\x01
(
\v
2
\x19
.memos.store.OAuth2ConfigH
\x00
R
\f
oauth2ConfigB
\b\n
"
+
"
\r
oauth2_config
\x18\x01
\x01
(
\v
2
\x19
.memos.store.OAuth2ConfigH
\x00
R
\f
oauth2ConfigB
\b\n
"
+
"
\x06
config
\"
g
\n
"
+
"
\x06
config
\"
\x86\x01
\n
"
+
"
\f
FieldMapping
\x12\x1e\n
"
+
"
\f
FieldMapping
\x12\x1e\n
"
+
"
\n
"
+
"
\n
"
+
"identifier
\x18\x01
\x01
(
\t
R
\n
"
+
"identifier
\x18\x01
\x01
(
\t
R
\n
"
+
"identifier
\x12
!
\n
"
+
"identifier
\x12
!
\n
"
+
"
\f
display_name
\x18\x02
\x01
(
\t
R
\v
displayName
\x12\x14\n
"
+
"
\f
display_name
\x18\x02
\x01
(
\t
R
\v
displayName
\x12\x14\n
"
+
"
\x05
email
\x18\x03
\x01
(
\t
R
\x05
email
\"\x84\x02\n
"
+
"
\x05
email
\x18\x03
\x01
(
\t
R
\x05
email
\x12\x1d\n
"
+
"
\n
"
+
"avatar_url
\x18\x04
\x01
(
\t
R
\t
avatarUrl
\"\x84\x02\n
"
+
"
\f
OAuth2Config
\x12\x1b\n
"
+
"
\f
OAuth2Config
\x12\x1b\n
"
+
"
\t
client_id
\x18\x01
\x01
(
\t
R
\b
clientId
\x12
#
\n
"
+
"
\t
client_id
\x18\x01
\x01
(
\t
R
\b
clientId
\x12
#
\n
"
+
"
\r
client_secret
\x18\x02
\x01
(
\t
R
\f
clientSecret
\x12\x19\n
"
+
"
\r
client_secret
\x18\x02
\x01
(
\t
R
\f
clientSecret
\x12\x19\n
"
+
...
...
proto/store/idp.proto
View file @
eb33a604
...
@@ -27,6 +27,7 @@ message FieldMapping {
...
@@ -27,6 +27,7 @@ message FieldMapping {
string
identifier
=
1
;
string
identifier
=
1
;
string
display_name
=
2
;
string
display_name
=
2
;
string
email
=
3
;
string
email
=
3
;
string
avatar_url
=
4
;
}
}
message
OAuth2Config
{
message
OAuth2Config
{
...
...
server/router/api/v1/auth_service.go
View file @
eb33a604
...
@@ -129,9 +129,10 @@ func (s *APIV1Service) SignInWithSSO(ctx context.Context, request *v1pb.SignInWi
...
@@ -129,9 +129,10 @@ func (s *APIV1Service) SignInWithSSO(ctx context.Context, request *v1pb.SignInWi
userCreate
:=
&
store
.
User
{
userCreate
:=
&
store
.
User
{
Username
:
userInfo
.
Identifier
,
Username
:
userInfo
.
Identifier
,
// The new signup user should be normal user by default.
// The new signup user should be normal user by default.
Role
:
store
.
RoleUser
,
Role
:
store
.
RoleUser
,
Nickname
:
userInfo
.
DisplayName
,
Nickname
:
userInfo
.
DisplayName
,
Email
:
userInfo
.
Email
,
Email
:
userInfo
.
Email
,
AvatarURL
:
userInfo
.
AvatarURL
,
}
}
password
,
err
:=
util
.
RandomString
(
20
)
password
,
err
:=
util
.
RandomString
(
20
)
if
err
!=
nil
{
if
err
!=
nil
{
...
...
web/src/types/proto/api/v1/idp_service.ts
View file @
eb33a604
...
@@ -64,6 +64,7 @@ export interface FieldMapping {
...
@@ -64,6 +64,7 @@ export interface FieldMapping {
identifier
:
string
;
identifier
:
string
;
displayName
:
string
;
displayName
:
string
;
email
:
string
;
email
:
string
;
avatarUrl
:
string
;
}
}
export
interface
OAuth2Config
{
export
interface
OAuth2Config
{
...
@@ -255,7 +256,7 @@ export const IdentityProviderConfig: MessageFns<IdentityProviderConfig> = {
...
@@ -255,7 +256,7 @@ export const IdentityProviderConfig: MessageFns<IdentityProviderConfig> = {
};
};
function
createBaseFieldMapping
():
FieldMapping
{
function
createBaseFieldMapping
():
FieldMapping
{
return
{
identifier
:
""
,
displayName
:
""
,
email
:
""
};
return
{
identifier
:
""
,
displayName
:
""
,
email
:
""
,
avatarUrl
:
""
};
}
}
export
const
FieldMapping
:
MessageFns
<
FieldMapping
>
=
{
export
const
FieldMapping
:
MessageFns
<
FieldMapping
>
=
{
...
@@ -269,6 +270,9 @@ export const FieldMapping: MessageFns<FieldMapping> = {
...
@@ -269,6 +270,9 @@ export const FieldMapping: MessageFns<FieldMapping> = {
if
(
message
.
email
!==
""
)
{
if
(
message
.
email
!==
""
)
{
writer
.
uint32
(
26
).
string
(
message
.
email
);
writer
.
uint32
(
26
).
string
(
message
.
email
);
}
}
if
(
message
.
avatarUrl
!==
""
)
{
writer
.
uint32
(
34
).
string
(
message
.
avatarUrl
);
}
return
writer
;
return
writer
;
},
},
...
@@ -303,6 +307,14 @@ export const FieldMapping: MessageFns<FieldMapping> = {
...
@@ -303,6 +307,14 @@ export const FieldMapping: MessageFns<FieldMapping> = {
message
.
email
=
reader
.
string
();
message
.
email
=
reader
.
string
();
continue
;
continue
;
}
}
case
4
:
{
if
(
tag
!==
34
)
{
break
;
}
message
.
avatarUrl
=
reader
.
string
();
continue
;
}
}
}
if
((
tag
&
7
)
===
4
||
tag
===
0
)
{
if
((
tag
&
7
)
===
4
||
tag
===
0
)
{
break
;
break
;
...
@@ -320,6 +332,7 @@ export const FieldMapping: MessageFns<FieldMapping> = {
...
@@ -320,6 +332,7 @@ export const FieldMapping: MessageFns<FieldMapping> = {
message
.
identifier
=
object
.
identifier
??
""
;
message
.
identifier
=
object
.
identifier
??
""
;
message
.
displayName
=
object
.
displayName
??
""
;
message
.
displayName
=
object
.
displayName
??
""
;
message
.
email
=
object
.
email
??
""
;
message
.
email
=
object
.
email
??
""
;
message
.
avatarUrl
=
object
.
avatarUrl
??
""
;
return
message
;
return
message
;
},
},
};
};
...
...
web/src/types/proto/google/protobuf/descriptor.ts
View file @
eb33a604
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment