Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dex
Project
Project
Details
Activity
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
go
dex
Commits
b38d3552
Commit
b38d3552
authored
Dec 01, 2016
by
rithu leena john
Committed by
GitHub
Dec 01, 2016
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #713 from ericchiang/example-app-state
cmd/example-app: use a non-empty state
parents
9d9ad4a5
aebb6818
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
2 deletions
+9
-2
main.go
cmd/example-app/main.go
+9
-2
No files found.
cmd/example-app/main.go
View file @
b38d3552
...
...
@@ -23,6 +23,8 @@ import (
"golang.org/x/oauth2"
)
const
exampleAppState
=
"I wish to wash my irish wristwatch"
type
app
struct
{
clientID
string
clientSecret
string
...
...
@@ -241,9 +243,9 @@ func (a *app) handleLogin(w http.ResponseWriter, r *http.Request) {
scopes
=
append
(
scopes
,
"openid"
,
"profile"
,
"email"
)
if
a
.
offlineAsScope
{
scopes
=
append
(
scopes
,
"offline_access"
)
authCodeURL
=
a
.
oauth2Config
(
scopes
)
.
AuthCodeURL
(
""
)
authCodeURL
=
a
.
oauth2Config
(
scopes
)
.
AuthCodeURL
(
exampleAppState
)
}
else
{
authCodeURL
=
a
.
oauth2Config
(
scopes
)
.
AuthCodeURL
(
""
,
oauth2
.
AccessTypeOffline
)
authCodeURL
=
a
.
oauth2Config
(
scopes
)
.
AuthCodeURL
(
exampleAppState
,
oauth2
.
AccessTypeOffline
)
}
http
.
Redirect
(
w
,
r
,
authCodeURL
,
http
.
StatusSeeOther
)
}
...
...
@@ -254,6 +256,11 @@ func (a *app) handleCallback(w http.ResponseWriter, r *http.Request) {
return
}
if
state
:=
r
.
FormValue
(
"state"
);
state
!=
exampleAppState
{
http
.
Error
(
w
,
fmt
.
Sprintf
(
"expected state %q got %q"
,
exampleAppState
,
state
),
http
.
StatusBadRequest
)
return
}
code
:=
r
.
FormValue
(
"code"
)
refresh
:=
r
.
FormValue
(
"refresh_token"
)
var
(
...
...
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