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
47a7d93f
Commit
47a7d93f
authored
Jan 21, 2019
by
bergquist
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
moves rotation into auth since both happens before c.Next()
parent
fd937e3d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
24 deletions
+24
-24
pkg/middleware/middleware.go
+22
-22
pkg/services/auth/auth_token.go
+2
-2
No files found.
pkg/middleware/middleware.go
View file @
47a7d93f
...
...
@@ -61,28 +61,6 @@ func GetContextHandler(ats *auth.UserAuthTokenService) macaron.Handler {
c
.
Map
(
ctx
)
//if signed in with token
rotated
,
err
:=
ats
.
RefreshToken
(
ctx
.
UserToken
,
ctx
.
RemoteAddr
(),
ctx
.
Req
.
UserAgent
())
if
err
!=
nil
{
ctx
.
Logger
.
Error
(
"failed to rotate token"
,
"error"
,
err
)
return
}
if
rotated
{
ctx
.
Logger
.
Info
(
"new token"
,
"unhashed token"
,
ctx
.
UserToken
.
UnhashedToken
)
ctx
.
Resp
.
Header
()
.
Del
(
"Set-Cookie"
)
cookie
:=
http
.
Cookie
{
Name
:
"grafana_session"
,
Value
:
url
.
QueryEscape
(
ctx
.
UserToken
.
UnhashedToken
),
HttpOnly
:
true
,
//MaxAge: 600,
Domain
:
setting
.
Domain
,
Path
:
setting
.
AppSubUrl
+
"/"
,
}
ctx
.
Resp
.
Header
()
.
Add
(
"Set-Cookie"
,
cookie
.
String
())
}
// update last seen every 5min
if
ctx
.
ShouldUpdateLastSeenAt
()
{
ctx
.
Logger
.
Debug
(
"Updating last user_seen_at"
,
"user_id"
,
ctx
.
UserId
)
...
...
@@ -114,6 +92,7 @@ func initContextWithAnonymousUser(ctx *m.ReqContext) bool {
}
func
initContextWithToken
(
ctx
*
m
.
ReqContext
,
orgID
int64
,
ts
*
auth
.
UserAuthTokenService
)
bool
{
//auth User
unhashedToken
:=
ctx
.
GetCookie
(
"grafana_session"
)
if
unhashedToken
==
""
{
return
false
...
...
@@ -135,6 +114,27 @@ func initContextWithToken(ctx *m.ReqContext, orgID int64, ts *auth.UserAuthToken
ctx
.
IsSignedIn
=
true
ctx
.
UserToken
=
user
//rotate session token if needed.
rotated
,
err
:=
ts
.
RefreshToken
(
ctx
.
UserToken
,
ctx
.
RemoteAddr
(),
ctx
.
Req
.
UserAgent
())
if
err
!=
nil
{
ctx
.
Logger
.
Error
(
"failed to rotate token"
,
"error"
,
err
,
"user.id"
,
user
.
UserId
,
"user_token.id"
,
user
.
Id
)
return
true
}
if
rotated
{
ctx
.
Logger
.
Info
(
"new token"
,
"unhashed token"
,
ctx
.
UserToken
.
UnhashedToken
)
ctx
.
Resp
.
Header
()
.
Del
(
"Set-Cookie"
)
cookie
:=
http
.
Cookie
{
Name
:
"grafana_session"
,
Value
:
url
.
QueryEscape
(
ctx
.
UserToken
.
UnhashedToken
),
HttpOnly
:
true
,
Domain
:
setting
.
Domain
,
Path
:
setting
.
AppSubUrl
+
"/"
,
}
ctx
.
Resp
.
Header
()
.
Add
(
"Set-Cookie"
,
cookie
.
String
())
}
return
true
}
...
...
pkg/services/auth/auth_token.go
View file @
47a7d93f
...
...
@@ -190,7 +190,7 @@ func (s *UserAuthTokenService) RefreshToken(token *models.UserAuthToken, clientI
needsRotation
=
rotatedAt
.
Before
(
now
()
.
Add
(
time
.
Duration
(
-
30
)
*
time
.
Second
))
}
s
.
log
.
Info
(
"refresh token"
,
"needs rotation?"
,
needsRotation
,
"auth_token_seen"
,
token
.
AuthTokenSeen
,
"rotated_at"
,
rotatedAt
,
"token.Id"
,
token
.
Id
)
s
.
log
.
Debug
(
"refresh token"
,
"needs rotation?"
,
needsRotation
,
"auth_token_seen"
,
token
.
AuthTokenSeen
,
"rotated_at"
,
rotatedAt
,
"token.Id"
,
token
.
Id
)
if
!
needsRotation
{
return
false
,
nil
}
...
...
@@ -216,7 +216,7 @@ func (s *UserAuthTokenService) RefreshToken(token *models.UserAuthToken, clientI
}
affected
,
_
:=
res
.
RowsAffected
()
s
.
log
.
Info
(
"rotated"
,
"affected"
,
affected
,
"auth_token_id"
,
token
.
Id
,
"userId"
,
token
.
UserId
,
"user_agent"
,
userAgent
,
"client_ip"
,
clientIP
)
s
.
log
.
Debug
(
"rotated"
,
"affected"
,
affected
,
"auth_token_id"
,
token
.
Id
,
"userId"
,
token
.
UserId
,
"user_agent"
,
userAgent
,
"client_ip"
,
clientIP
)
if
affected
>
0
{
token
.
UnhashedToken
=
newToken
return
true
,
nil
...
...
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