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
81443bf8
Commit
81443bf8
authored
Oct 08, 2016
by
Eric Perrino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a state parameter for all OAuth requests
parent
913f17ee
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
1 deletions
+20
-1
pkg/api/login_oauth.go
+19
-1
pkg/middleware/session.go
+1
-0
No files found.
pkg/api/login_oauth.go
View file @
81443bf8
...
...
@@ -3,6 +3,8 @@ package api
import
(
"errors"
"fmt"
"crypto/rand"
"encoding/base64"
"golang.org/x/oauth2"
...
...
@@ -14,6 +16,12 @@ import (
"github.com/grafana/grafana/pkg/social"
)
func
GenStateString
()
string
{
rnd
:=
make
([]
byte
,
32
)
rand
.
Read
(
rnd
)
return
base64
.
StdEncoding
.
EncodeToString
(
rnd
)
}
func
OAuthLogin
(
ctx
*
middleware
.
Context
)
{
if
setting
.
OAuthService
==
nil
{
ctx
.
Handle
(
404
,
"login.OAuthLogin(oauth service not enabled)"
,
nil
)
...
...
@@ -29,7 +37,17 @@ func OAuthLogin(ctx *middleware.Context) {
code
:=
ctx
.
Query
(
"code"
)
if
code
==
""
{
ctx
.
Redirect
(
connect
.
AuthCodeURL
(
""
,
oauth2
.
AccessTypeOnline
))
state
:=
GenStateString
()
ctx
.
Session
.
Set
(
middleware
.
SESS_KEY_OAUTH_STATE
,
state
)
ctx
.
Redirect
(
connect
.
AuthCodeURL
(
state
,
oauth2
.
AccessTypeOnline
))
return
}
// verify state string
savedState
:=
ctx
.
Session
.
Get
(
middleware
.
SESS_KEY_OAUTH_STATE
)
.
(
string
)
queryState
:=
ctx
.
Query
(
"state"
)
if
savedState
!=
queryState
{
ctx
.
Handle
(
500
,
"login.OAuthLogin(state mismatch)"
,
nil
)
return
}
...
...
pkg/middleware/session.go
View file @
81443bf8
...
...
@@ -13,6 +13,7 @@ import (
const
(
SESS_KEY_USERID
=
"uid"
SESS_KEY_OAUTH_STATE
=
"state"
)
var
sessionManager
*
session
.
Manager
...
...
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