Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nexpie-grafana-theme
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Registry
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kornkitt Poolsup
nexpie-grafana-theme
Commits
9d005c50
Unverified
Commit
9d005c50
authored
Mar 06, 2018
by
Dan Cech
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
only use jwt token if it contains an email address
parent
7ba9e2e6
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
26 additions
and
22 deletions
+26
-22
pkg/social/generic_oauth.go
+26
-22
No files found.
pkg/social/generic_oauth.go
View file @
9d005c50
...
...
@@ -180,6 +180,7 @@ type UserInfoJson struct {
func
(
s
*
SocialGenericOAuth
)
UserInfo
(
client
*
http
.
Client
,
token
*
oauth2
.
Token
)
(
*
BasicUserInfo
,
error
)
{
var
data
UserInfoJson
var
err
error
if
s
.
extractToken
(
&
data
,
token
)
!=
true
{
response
,
err
:=
HttpGet
(
client
,
s
.
apiUrl
)
...
...
@@ -193,21 +194,18 @@ func (s *SocialGenericOAuth) UserInfo(client *http.Client, token *oauth2.Token)
}
}
name
,
err
:=
s
.
extractName
(
data
)
if
err
!=
nil
{
return
nil
,
err
}
name
:=
s
.
extractName
(
&
data
)
email
,
err
:=
s
.
extractEmail
(
data
,
client
)
email
:=
s
.
extractEmail
(
&
data
)
if
email
==
""
{
email
,
err
=
s
.
FetchPrivateEmail
(
client
)
if
err
!=
nil
{
return
nil
,
err
}
login
,
err
:=
s
.
extractLogin
(
data
,
email
)
if
err
!=
nil
{
return
nil
,
err
}
login
:=
s
.
extractLogin
(
&
data
,
email
)
userInfo
:=
&
BasicUserInfo
{
Name
:
name
,
Login
:
login
,
...
...
@@ -251,49 +249,55 @@ func (s *SocialGenericOAuth) extractToken(data *UserInfoJson, token *oauth2.Toke
return
false
}
email
:=
s
.
extractEmail
(
data
)
if
email
==
""
{
s
.
log
.
Debug
(
"No email found in id_token"
,
"json"
,
string
(
payload
),
"data"
,
data
)
return
false
}
s
.
log
.
Debug
(
"Received id_token"
,
"json"
,
string
(
payload
),
"data"
,
data
)
return
true
}
func
(
s
*
SocialGenericOAuth
)
extractEmail
(
data
UserInfoJson
,
client
*
http
.
Client
)
(
string
,
error
)
{
func
(
s
*
SocialGenericOAuth
)
extractEmail
(
data
*
UserInfoJson
)
string
{
if
data
.
Email
!=
""
{
return
data
.
Email
,
nil
return
data
.
Email
}
if
data
.
Attributes
[
"email:primary"
]
!=
nil
{
return
data
.
Attributes
[
"email:primary"
][
0
]
,
nil
return
data
.
Attributes
[
"email:primary"
][
0
]
}
if
data
.
Upn
!=
""
{
emailAddr
,
emailErr
:=
mail
.
ParseAddress
(
data
.
Upn
)
if
emailErr
==
nil
{
return
emailAddr
.
Address
,
nil
return
emailAddr
.
Address
}
}
return
s
.
FetchPrivateEmail
(
client
)
return
""
}
func
(
s
*
SocialGenericOAuth
)
extractLogin
(
data
UserInfoJson
,
email
string
)
(
string
,
error
)
{
func
(
s
*
SocialGenericOAuth
)
extractLogin
(
data
*
UserInfoJson
,
email
string
)
string
{
if
data
.
Login
!=
""
{
return
data
.
Login
,
nil
return
data
.
Login
}
if
data
.
Username
!=
""
{
return
data
.
Username
,
nil
return
data
.
Username
}
return
email
,
nil
return
email
}
func
(
s
*
SocialGenericOAuth
)
extractName
(
data
UserInfoJson
)
(
string
,
error
)
{
func
(
s
*
SocialGenericOAuth
)
extractName
(
data
*
UserInfoJson
)
string
{
if
data
.
Name
!=
""
{
return
data
.
Name
,
nil
return
data
.
Name
}
if
data
.
DisplayName
!=
""
{
return
data
.
DisplayName
,
nil
return
data
.
DisplayName
}
return
""
,
nil
return
""
}
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