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
e2c428fc
Commit
e2c428fc
authored
May 06, 2016
by
Bobby Rullo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
examples/app: Show refresh token as well
parent
ea4c04fd
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
6 deletions
+40
-6
main.go
examples/app/main.go
+40
-6
No files found.
examples/app/main.go
View file @
e2c428fc
...
...
@@ -14,10 +14,13 @@ import (
"os"
"time"
"github.com/coreos/go-oidc/jose"
"github.com/coreos/go-oidc/oauth2"
"github.com/coreos/go-oidc/oidc"
pflag
"github.com/coreos/dex/pkg/flag"
phttp
"github.com/coreos/dex/pkg/http"
"github.com/coreos/dex/pkg/log"
"github.com/coreos/go-oidc/oidc"
)
func
main
()
{
...
...
@@ -104,6 +107,7 @@ func main() {
ProviderConfig
:
cfg
,
Credentials
:
cc
,
RedirectURL
:
*
redirectURL
,
Scope
:
append
(
oidc
.
DefaultScope
,
"offline_access"
),
}
client
,
err
:=
oidc
.
NewClient
(
ccfg
)
...
...
@@ -229,21 +233,51 @@ func handleCallbackFunc(c *oidc.Client) http.HandlerFunc {
return
}
tok
,
err
:=
c
.
ExchangeAuthCode
(
code
)
tok
ens
,
err
:=
exchangeAuthCode
(
c
,
code
)
if
err
!=
nil
{
phttp
.
WriteError
(
w
,
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"unable to verify auth code with issuer: %v"
,
err
))
phttp
.
WriteError
(
w
,
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"unable to verify auth code with issuer: %v"
,
err
))
return
}
tok
,
err
:=
jose
.
ParseJWT
(
tokens
.
IDToken
)
if
err
!=
nil
{
phttp
.
WriteError
(
w
,
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"unable to parse JWT: %v"
,
err
))
return
}
claims
,
err
:=
tok
.
Claims
()
if
err
!=
nil
{
phttp
.
WriteError
(
w
,
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"unable to construct claims: %v"
,
err
))
phttp
.
WriteError
(
w
,
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"unable to construct claims: %v"
,
err
))
return
}
s
:=
fmt
.
Sprintf
(
`<html><body><p>Token: %v</p><p>Claims: %v </p>
s
:=
fmt
.
Sprintf
(
`
<html>
<body>
<p> Token: %v</p>
<p> Claims: %v </p>
<a href="/resend?jwt=%s">Resend Verification Email</a>
</body></html>`
,
tok
.
Encode
(),
claims
,
tok
.
Encode
())
<p> Refresh Token: %v </p>
</body>
</html>`
,
tok
.
Encode
(),
claims
,
tok
.
Encode
(),
tokens
.
RefreshToken
)
w
.
Write
([]
byte
(
s
))
}
}
func
exchangeAuthCode
(
c
*
oidc
.
Client
,
code
string
)
(
oauth2
.
TokenResponse
,
error
)
{
oac
,
err
:=
c
.
OAuthClient
()
if
err
!=
nil
{
return
oauth2
.
TokenResponse
{},
err
}
t
,
err
:=
oac
.
RequestToken
(
oauth2
.
GrantTypeAuthCode
,
code
)
if
err
!=
nil
{
return
oauth2
.
TokenResponse
{},
err
}
return
t
,
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