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
dc979c1d
Commit
dc979c1d
authored
Sep 12, 2016
by
Moto Ishizawa
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
server: use time.Time instead of int64 for token expiration time
parent
25e4228e
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
15 deletions
+15
-15
cross_client_test.go
server/cross_client_test.go
+2
-2
http.go
server/http.go
+5
-5
server.go
server/server.go
+0
-0
server_test.go
server/server_test.go
+8
-8
No files found.
server/cross_client_test.go
View file @
dc979c1d
...
...
@@ -283,7 +283,7 @@ func TestServerCodeTokenCrossClient(t *testing.T) {
t
.
Fatalf
(
"case %d: unexpected error: %v"
,
i
,
err
)
}
jwt
,
token
,
expires
In
,
err
:=
f
.
srv
.
CodeToken
(
f
.
clientCreds
[
tt
.
clientID
],
key
)
jwt
,
token
,
expires
At
,
err
:=
f
.
srv
.
CodeToken
(
f
.
clientCreds
[
tt
.
clientID
],
key
)
if
err
!=
nil
{
t
.
Fatalf
(
"case %d: unexpected error: %v"
,
i
,
err
)
}
...
...
@@ -293,7 +293,7 @@ func TestServerCodeTokenCrossClient(t *testing.T) {
if
token
!=
tt
.
refreshToken
{
t
.
Errorf
(
"case %d: expect refresh token %q, got %q"
,
i
,
tt
.
refreshToken
,
token
)
}
if
expires
In
==
0
{
if
expires
At
.
IsZero
()
{
t
.
Errorf
(
"case %d: expect non-zero expiration time"
,
i
)
}
...
...
server/http.go
View file @
dc979c1d
...
...
@@ -491,7 +491,7 @@ func handleTokenFunc(srv OIDCServer) http.HandlerFunc {
var
jwt
*
jose
.
JWT
var
refreshToken
string
var
expires
In
int64
var
expires
At
time
.
Time
grantType
:=
r
.
PostForm
.
Get
(
"grant_type"
)
switch
grantType
{
...
...
@@ -502,14 +502,14 @@ func handleTokenFunc(srv OIDCServer) http.HandlerFunc {
writeTokenError
(
w
,
oauth2
.
NewError
(
oauth2
.
ErrorInvalidRequest
),
state
)
return
}
jwt
,
refreshToken
,
expires
In
,
err
=
srv
.
CodeToken
(
creds
,
code
)
jwt
,
refreshToken
,
expires
At
,
err
=
srv
.
CodeToken
(
creds
,
code
)
if
err
!=
nil
{
log
.
Errorf
(
"couldn't exchange code for token: %v"
,
err
)
writeTokenError
(
w
,
err
,
state
)
return
}
case
oauth2
.
GrantTypeClientCreds
:
jwt
,
expires
In
,
err
=
srv
.
ClientCredsToken
(
creds
)
jwt
,
expires
At
,
err
=
srv
.
ClientCredsToken
(
creds
)
if
err
!=
nil
{
log
.
Errorf
(
"couldn't creds for token: %v"
,
err
)
writeTokenError
(
w
,
err
,
state
)
...
...
@@ -522,7 +522,7 @@ func handleTokenFunc(srv OIDCServer) http.HandlerFunc {
writeTokenError
(
w
,
oauth2
.
NewError
(
oauth2
.
ErrorInvalidRequest
),
state
)
return
}
jwt
,
refreshToken
,
expires
In
,
err
=
srv
.
RefreshToken
(
creds
,
strings
.
Split
(
scopes
,
" "
),
token
)
jwt
,
refreshToken
,
expires
At
,
err
=
srv
.
RefreshToken
(
creds
,
strings
.
Split
(
scopes
,
" "
),
token
)
if
err
!=
nil
{
writeTokenError
(
w
,
err
,
state
)
return
...
...
@@ -538,7 +538,7 @@ func handleTokenFunc(srv OIDCServer) http.HandlerFunc {
IDToken
:
jwt
.
Encode
(),
TokenType
:
"bearer"
,
RefreshToken
:
refreshToken
,
ExpiresIn
:
expiresIn
,
ExpiresIn
:
int64
(
expiresAt
.
Sub
(
time
.
Now
())
.
Seconds
())
,
}
b
,
err
:=
json
.
Marshal
(
t
)
...
...
server/server.go
View file @
dc979c1d
This diff is collapsed.
Click to expand it.
server/server_test.go
View file @
dc979c1d
...
...
@@ -443,7 +443,7 @@ func TestServerCodeToken(t *testing.T) {
t
.
Fatalf
(
"case %d: unexpected error: %v"
,
i
,
err
)
}
jwt
,
token
,
expires
In
,
err
:=
f
.
srv
.
CodeToken
(
oidc
.
ClientCredentials
{
jwt
,
token
,
expires
At
,
err
:=
f
.
srv
.
CodeToken
(
oidc
.
ClientCredentials
{
ID
:
testClientID
,
Secret
:
clientTestSecret
},
key
)
if
err
!=
nil
{
...
...
@@ -455,7 +455,7 @@ func TestServerCodeToken(t *testing.T) {
if
token
!=
tt
.
refreshToken
{
t
.
Fatalf
(
"case %d: expect refresh token %q, got %q"
,
i
,
tt
.
refreshToken
,
token
)
}
if
expires
In
==
0
{
if
expires
At
.
IsZero
()
{
t
.
Fatalf
(
"case %d: expect non-zero expiration time"
,
i
)
}
}
...
...
@@ -478,7 +478,7 @@ func TestServerTokenUnrecognizedKey(t *testing.T) {
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
jwt
,
token
,
expires
In
,
err
:=
f
.
srv
.
CodeToken
(
testClientCredentials
,
"foo"
)
jwt
,
token
,
expires
At
,
err
:=
f
.
srv
.
CodeToken
(
testClientCredentials
,
"foo"
)
if
err
==
nil
{
t
.
Fatalf
(
"Expected non-nil error"
)
}
...
...
@@ -488,7 +488,7 @@ func TestServerTokenUnrecognizedKey(t *testing.T) {
if
token
!=
""
{
t
.
Fatalf
(
"Expected empty refresh token"
)
}
if
expiresIn
!=
0
{
if
!
expiresAt
.
IsZero
()
{
t
.
Fatalf
(
"Expected zero expiration time"
)
}
}
...
...
@@ -586,7 +586,7 @@ func TestServerTokenFail(t *testing.T) {
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
jwt
,
token
,
expires
In
,
err
:=
f
.
srv
.
CodeToken
(
tt
.
argCC
,
tt
.
argKey
)
jwt
,
token
,
expires
At
,
err
:=
f
.
srv
.
CodeToken
(
tt
.
argCC
,
tt
.
argKey
)
if
token
!=
tt
.
refreshToken
{
fmt
.
Printf
(
"case %d: expect refresh token %q, got %q
\n
"
,
i
,
tt
.
refreshToken
,
token
)
t
.
Fatalf
(
"case %d: expect refresh token %q, got %q"
,
i
,
tt
.
refreshToken
,
token
)
...
...
@@ -601,8 +601,8 @@ func TestServerTokenFail(t *testing.T) {
if
err
!=
nil
&&
jwt
!=
nil
{
t
.
Errorf
(
"case %d: got non-nil JWT %v"
,
i
,
jwt
)
}
if
err
==
nil
&&
expires
In
==
0
{
t
.
Errorf
(
"case %d: got zero expiration time %v"
,
i
,
expires
In
)
if
err
==
nil
&&
expires
At
.
IsZero
()
{
t
.
Errorf
(
"case %d: got zero expiration time %v"
,
i
,
expires
At
)
}
}
}
...
...
@@ -885,7 +885,7 @@ func TestServerRefreshToken(t *testing.T) {
t
.
Errorf
(
"Case %d: want=%v, got=%v"
,
i
,
tt
.
expectedRefreshToken
,
refreshToken
)
}
if
err
==
nil
&&
expiresIn
==
0
{
if
err
==
nil
&&
expiresIn
.
IsZero
()
{
t
.
Errorf
(
"case %d: got zero expiration time %v"
,
i
,
expiresIn
)
}
}
...
...
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