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
066fd859
Commit
066fd859
authored
Aug 28, 2015
by
Yifan Gu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
session: add 'scope' field in session.
parent
d87b5c9b
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
28 additions
and
18 deletions
+28
-18
0007_session_scope.sql
db/migrations/0007_session_scope.sql
+2
-0
assets.go
db/migrations/assets.go
+0
-0
session.go
db/session.go
+4
-0
oidc_test.go
integration/oidc_test.go
+1
-1
http.go
server/http.go
+1
-1
password_test.go
server/password_test.go
+1
-1
register_test.go
server/register_test.go
+1
-1
server.go
server/server.go
+3
-3
server_test.go
server/server_test.go
+5
-5
manager.go
session/manager.go
+2
-1
manager_test.go
session/manager_test.go
+5
-5
session.go
session/session.go
+3
-0
No files found.
db/migrations/0007_session_scope.sql
0 → 100644
View file @
066fd859
-- +migrate Up
ALTER
TABLE
session
ADD
COLUMN
"scope"
text
;
db/migrations/assets.go
View file @
066fd859
This diff is collapsed.
Click to expand it.
db/session.go
View file @
066fd859
...
@@ -5,6 +5,7 @@ import (
...
@@ -5,6 +5,7 @@ import (
"errors"
"errors"
"fmt"
"fmt"
"net/url"
"net/url"
"strings"
"time"
"time"
"github.com/go-gorp/gorp"
"github.com/go-gorp/gorp"
...
@@ -42,6 +43,7 @@ type sessionModel struct {
...
@@ -42,6 +43,7 @@ type sessionModel struct {
UserID
string
`db:"user_id"`
UserID
string
`db:"user_id"`
Register
bool
`db:"register"`
Register
bool
`db:"register"`
Nonce
string
`db:"nonce"`
Nonce
string
`db:"nonce"`
Scope
string
`db:"scope"`
}
}
func
(
s
*
sessionModel
)
session
()
(
*
session
.
Session
,
error
)
{
func
(
s
*
sessionModel
)
session
()
(
*
session
.
Session
,
error
)
{
...
@@ -71,6 +73,7 @@ func (s *sessionModel) session() (*session.Session, error) {
...
@@ -71,6 +73,7 @@ func (s *sessionModel) session() (*session.Session, error) {
UserID
:
s
.
UserID
,
UserID
:
s
.
UserID
,
Register
:
s
.
Register
,
Register
:
s
.
Register
,
Nonce
:
s
.
Nonce
,
Nonce
:
s
.
Nonce
,
Scope
:
strings
.
Fields
(
s
.
Scope
),
}
}
if
s
.
CreatedAt
!=
0
{
if
s
.
CreatedAt
!=
0
{
...
@@ -101,6 +104,7 @@ func newSessionModel(s *session.Session) (*sessionModel, error) {
...
@@ -101,6 +104,7 @@ func newSessionModel(s *session.Session) (*sessionModel, error) {
UserID
:
s
.
UserID
,
UserID
:
s
.
UserID
,
Register
:
s
.
Register
,
Register
:
s
.
Register
,
Nonce
:
s
.
Nonce
,
Nonce
:
s
.
Nonce
,
Scope
:
strings
.
Join
(
s
.
Scope
,
" "
),
}
}
if
!
s
.
CreatedAt
.
IsZero
()
{
if
!
s
.
CreatedAt
.
IsZero
()
{
...
...
integration/oidc_test.go
View file @
066fd859
...
@@ -196,7 +196,7 @@ func TestHTTPExchangeTokenRefreshToken(t *testing.T) {
...
@@ -196,7 +196,7 @@ func TestHTTPExchangeTokenRefreshToken(t *testing.T) {
// this will actually happen due to some interaction between the
// this will actually happen due to some interaction between the
// end-user and a remote identity provider
// end-user and a remote identity provider
sessionID
,
err
:=
sm
.
NewSession
(
"bogus_idpc"
,
ci
.
Credentials
.
ID
,
"bogus"
,
url
.
URL
{},
""
,
false
)
sessionID
,
err
:=
sm
.
NewSession
(
"bogus_idpc"
,
ci
.
Credentials
.
ID
,
"bogus"
,
url
.
URL
{},
""
,
false
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
...
...
server/http.go
View file @
066fd859
...
@@ -332,7 +332,7 @@ func handleAuthFunc(srv OIDCServer, idpcs []connector.Connector, tpl *template.T
...
@@ -332,7 +332,7 @@ func handleAuthFunc(srv OIDCServer, idpcs []connector.Connector, tpl *template.T
nonce
:=
q
.
Get
(
"nonce"
)
nonce
:=
q
.
Get
(
"nonce"
)
key
,
err
:=
srv
.
NewSession
(
connectorID
,
acr
.
ClientID
,
acr
.
State
,
redirectURL
,
nonce
,
register
)
key
,
err
:=
srv
.
NewSession
(
connectorID
,
acr
.
ClientID
,
acr
.
State
,
redirectURL
,
nonce
,
register
,
acr
.
Scope
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Errorf
(
"Error creating new session: %v: "
,
err
)
log
.
Errorf
(
"Error creating new session: %v: "
,
err
)
redirectAuthError
(
w
,
err
,
acr
.
State
,
redirectURL
)
redirectAuthError
(
w
,
err
,
acr
.
State
,
redirectURL
)
...
...
server/password_test.go
View file @
066fd859
...
@@ -245,7 +245,7 @@ func TestSendResetPasswordEmailHandler(t *testing.T) {
...
@@ -245,7 +245,7 @@ func TestSendResetPasswordEmailHandler(t *testing.T) {
t
.
Fatalf
(
"case %d: could not make test fixtures: %v"
,
i
,
err
)
t
.
Fatalf
(
"case %d: could not make test fixtures: %v"
,
i
,
err
)
}
}
_
,
err
=
f
.
srv
.
NewSession
(
"local"
,
"XXX"
,
""
,
f
.
redirectURL
,
""
,
true
)
_
,
err
=
f
.
srv
.
NewSession
(
"local"
,
"XXX"
,
""
,
f
.
redirectURL
,
""
,
true
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"case %d: could not create new session: %v"
,
i
,
err
)
t
.
Fatalf
(
"case %d: could not create new session: %v"
,
i
,
err
)
}
}
...
...
server/register_test.go
View file @
066fd859
...
@@ -197,7 +197,7 @@ func TestHandleRegister(t *testing.T) {
...
@@ -197,7 +197,7 @@ func TestHandleRegister(t *testing.T) {
t
.
Fatalf
(
"case %d: could not make test fixtures: %v"
,
i
,
err
)
t
.
Fatalf
(
"case %d: could not make test fixtures: %v"
,
i
,
err
)
}
}
key
,
err
:=
f
.
srv
.
NewSession
(
tt
.
connID
,
"XXX"
,
""
,
f
.
redirectURL
,
""
,
true
)
key
,
err
:=
f
.
srv
.
NewSession
(
tt
.
connID
,
"XXX"
,
""
,
f
.
redirectURL
,
""
,
true
,
nil
)
t
.
Logf
(
"case %d: key for NewSession: %v"
,
i
,
key
)
t
.
Logf
(
"case %d: key for NewSession: %v"
,
i
,
key
)
if
tt
.
attachRemote
{
if
tt
.
attachRemote
{
...
...
server/server.go
View file @
066fd859
...
@@ -39,7 +39,7 @@ const (
...
@@ -39,7 +39,7 @@ const (
type
OIDCServer
interface
{
type
OIDCServer
interface
{
ClientMetadata
(
string
)
(
*
oidc
.
ClientMetadata
,
error
)
ClientMetadata
(
string
)
(
*
oidc
.
ClientMetadata
,
error
)
NewSession
(
connectorID
,
clientID
,
clientState
string
,
redirectURL
url
.
URL
,
nonce
string
,
register
bool
)
(
string
,
error
)
NewSession
(
connectorID
,
clientID
,
clientState
string
,
redirectURL
url
.
URL
,
nonce
string
,
register
bool
,
scope
[]
string
)
(
string
,
error
)
Login
(
oidc
.
Identity
,
string
)
(
string
,
error
)
Login
(
oidc
.
Identity
,
string
)
(
string
,
error
)
// CodeToken exchanges a code for an ID token and a refresh token string on success.
// CodeToken exchanges a code for an ID token and a refresh token string on success.
CodeToken
(
creds
oidc
.
ClientCredentials
,
sessionKey
string
)
(
*
jose
.
JWT
,
string
,
error
)
CodeToken
(
creds
oidc
.
ClientCredentials
,
sessionKey
string
)
(
*
jose
.
JWT
,
string
,
error
)
...
@@ -263,8 +263,8 @@ func (s *Server) ClientMetadata(clientID string) (*oidc.ClientMetadata, error) {
...
@@ -263,8 +263,8 @@ func (s *Server) ClientMetadata(clientID string) (*oidc.ClientMetadata, error) {
return
s
.
ClientIdentityRepo
.
Metadata
(
clientID
)
return
s
.
ClientIdentityRepo
.
Metadata
(
clientID
)
}
}
func
(
s
*
Server
)
NewSession
(
ipdcID
,
clientID
,
clientState
string
,
redirectURL
url
.
URL
,
nonce
string
,
register
bool
)
(
string
,
error
)
{
func
(
s
*
Server
)
NewSession
(
ipdcID
,
clientID
,
clientState
string
,
redirectURL
url
.
URL
,
nonce
string
,
register
bool
,
scope
[]
string
)
(
string
,
error
)
{
sessionID
,
err
:=
s
.
SessionManager
.
NewSession
(
ipdcID
,
clientID
,
clientState
,
redirectURL
,
nonce
,
register
)
sessionID
,
err
:=
s
.
SessionManager
.
NewSession
(
ipdcID
,
clientID
,
clientState
,
redirectURL
,
nonce
,
register
,
scope
)
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
}
}
...
...
server/server_test.go
View file @
066fd859
...
@@ -139,7 +139,7 @@ func TestServerNewSession(t *testing.T) {
...
@@ -139,7 +139,7 @@ func TestServerNewSession(t *testing.T) {
},
},
}
}
key
,
err
:=
srv
.
NewSession
(
"bogus_idpc"
,
ci
.
Credentials
.
ID
,
state
,
ci
.
Metadata
.
RedirectURLs
[
0
],
nonce
,
false
)
key
,
err
:=
srv
.
NewSession
(
"bogus_idpc"
,
ci
.
Credentials
.
ID
,
state
,
ci
.
Metadata
.
RedirectURLs
[
0
],
nonce
,
false
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
...
@@ -195,7 +195,7 @@ func TestServerLogin(t *testing.T) {
...
@@ -195,7 +195,7 @@ func TestServerLogin(t *testing.T) {
sm
:=
session
.
NewSessionManager
(
session
.
NewSessionRepo
(),
session
.
NewSessionKeyRepo
())
sm
:=
session
.
NewSessionManager
(
session
.
NewSessionRepo
(),
session
.
NewSessionKeyRepo
())
sm
.
GenerateCode
=
staticGenerateCodeFunc
(
"fakecode"
)
sm
.
GenerateCode
=
staticGenerateCodeFunc
(
"fakecode"
)
sessionID
,
err
:=
sm
.
NewSession
(
"test_connector_id"
,
ci
.
Credentials
.
ID
,
"bogus"
,
ci
.
Metadata
.
RedirectURLs
[
0
],
""
,
false
)
sessionID
,
err
:=
sm
.
NewSession
(
"test_connector_id"
,
ci
.
Credentials
.
ID
,
"bogus"
,
ci
.
Metadata
.
RedirectURLs
[
0
],
""
,
false
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
...
@@ -292,7 +292,7 @@ func TestServerCodeToken(t *testing.T) {
...
@@ -292,7 +292,7 @@ func TestServerCodeToken(t *testing.T) {
RefreshTokenRepo
:
refreshTokenRepo
,
RefreshTokenRepo
:
refreshTokenRepo
,
}
}
sessionID
,
err
:=
sm
.
NewSession
(
"bogus_idpc"
,
ci
.
Credentials
.
ID
,
"bogus"
,
url
.
URL
{},
""
,
false
)
sessionID
,
err
:=
sm
.
NewSession
(
"bogus_idpc"
,
ci
.
Credentials
.
ID
,
"bogus"
,
url
.
URL
{},
""
,
false
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
...
@@ -343,7 +343,7 @@ func TestServerTokenUnrecognizedKey(t *testing.T) {
...
@@ -343,7 +343,7 @@ func TestServerTokenUnrecognizedKey(t *testing.T) {
ClientIdentityRepo
:
ciRepo
,
ClientIdentityRepo
:
ciRepo
,
}
}
sessionID
,
err
:=
sm
.
NewSession
(
"connector_id"
,
ci
.
Credentials
.
ID
,
"bogus"
,
url
.
URL
{},
""
,
false
)
sessionID
,
err
:=
sm
.
NewSession
(
"connector_id"
,
ci
.
Credentials
.
ID
,
"bogus"
,
url
.
URL
{},
""
,
false
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
...
@@ -416,7 +416,7 @@ func TestServerTokenFail(t *testing.T) {
...
@@ -416,7 +416,7 @@ func TestServerTokenFail(t *testing.T) {
sm
:=
session
.
NewSessionManager
(
session
.
NewSessionRepo
(),
session
.
NewSessionKeyRepo
())
sm
:=
session
.
NewSessionManager
(
session
.
NewSessionRepo
(),
session
.
NewSessionKeyRepo
())
sm
.
GenerateCode
=
func
()
(
string
,
error
)
{
return
keyFixture
,
nil
}
sm
.
GenerateCode
=
func
()
(
string
,
error
)
{
return
keyFixture
,
nil
}
sessionID
,
err
:=
sm
.
NewSession
(
"connector_id"
,
ccFixture
.
ID
,
"bogus"
,
url
.
URL
{},
""
,
false
)
sessionID
,
err
:=
sm
.
NewSession
(
"connector_id"
,
ccFixture
.
ID
,
"bogus"
,
url
.
URL
{},
""
,
false
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
...
...
session/manager.go
View file @
066fd859
...
@@ -44,7 +44,7 @@ type SessionManager struct {
...
@@ -44,7 +44,7 @@ type SessionManager struct {
keys
SessionKeyRepo
keys
SessionKeyRepo
}
}
func
(
m
*
SessionManager
)
NewSession
(
connectorID
,
clientID
,
clientState
string
,
redirectURL
url
.
URL
,
nonce
string
,
register
bool
)
(
string
,
error
)
{
func
(
m
*
SessionManager
)
NewSession
(
connectorID
,
clientID
,
clientState
string
,
redirectURL
url
.
URL
,
nonce
string
,
register
bool
,
scope
[]
string
)
(
string
,
error
)
{
sID
,
err
:=
m
.
GenerateCode
()
sID
,
err
:=
m
.
GenerateCode
()
if
err
!=
nil
{
if
err
!=
nil
{
return
""
,
err
return
""
,
err
...
@@ -62,6 +62,7 @@ func (m *SessionManager) NewSession(connectorID, clientID, clientState string, r
...
@@ -62,6 +62,7 @@ func (m *SessionManager) NewSession(connectorID, clientID, clientState string, r
RedirectURL
:
redirectURL
,
RedirectURL
:
redirectURL
,
Register
:
register
,
Register
:
register
,
Nonce
:
nonce
,
Nonce
:
nonce
,
Scope
:
scope
,
}
}
err
=
m
.
sessions
.
Create
(
s
)
err
=
m
.
sessions
.
Create
(
s
)
...
...
session/manager_test.go
View file @
066fd859
...
@@ -16,7 +16,7 @@ func staticGenerateCodeFunc(code string) GenerateCodeFunc {
...
@@ -16,7 +16,7 @@ func staticGenerateCodeFunc(code string) GenerateCodeFunc {
func
TestSessionManagerNewSession
(
t
*
testing
.
T
)
{
func
TestSessionManagerNewSession
(
t
*
testing
.
T
)
{
sm
:=
NewSessionManager
(
NewSessionRepo
(),
NewSessionKeyRepo
())
sm
:=
NewSessionManager
(
NewSessionRepo
(),
NewSessionKeyRepo
())
sm
.
GenerateCode
=
staticGenerateCodeFunc
(
"boo"
)
sm
.
GenerateCode
=
staticGenerateCodeFunc
(
"boo"
)
got
,
err
:=
sm
.
NewSession
(
"bogus_idpc"
,
"XXX"
,
"bogus"
,
url
.
URL
{},
""
,
false
)
got
,
err
:=
sm
.
NewSession
(
"bogus_idpc"
,
"XXX"
,
"bogus"
,
url
.
URL
{},
""
,
false
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
...
@@ -27,7 +27,7 @@ func TestSessionManagerNewSession(t *testing.T) {
...
@@ -27,7 +27,7 @@ func TestSessionManagerNewSession(t *testing.T) {
func
TestSessionAttachRemoteIdentityTwice
(
t
*
testing
.
T
)
{
func
TestSessionAttachRemoteIdentityTwice
(
t
*
testing
.
T
)
{
sm
:=
NewSessionManager
(
NewSessionRepo
(),
NewSessionKeyRepo
())
sm
:=
NewSessionManager
(
NewSessionRepo
(),
NewSessionKeyRepo
())
sessionID
,
err
:=
sm
.
NewSession
(
"bogus_idpc"
,
"XXX"
,
"bogus"
,
url
.
URL
{},
""
,
false
)
sessionID
,
err
:=
sm
.
NewSession
(
"bogus_idpc"
,
"XXX"
,
"bogus"
,
url
.
URL
{},
""
,
false
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
...
@@ -44,7 +44,7 @@ func TestSessionAttachRemoteIdentityTwice(t *testing.T) {
...
@@ -44,7 +44,7 @@ func TestSessionAttachRemoteIdentityTwice(t *testing.T) {
func
TestSessionManagerExchangeKey
(
t
*
testing
.
T
)
{
func
TestSessionManagerExchangeKey
(
t
*
testing
.
T
)
{
sm
:=
NewSessionManager
(
NewSessionRepo
(),
NewSessionKeyRepo
())
sm
:=
NewSessionManager
(
NewSessionRepo
(),
NewSessionKeyRepo
())
sessionID
,
err
:=
sm
.
NewSession
(
"connector_id"
,
"XXX"
,
"bogus"
,
url
.
URL
{},
""
,
false
)
sessionID
,
err
:=
sm
.
NewSession
(
"connector_id"
,
"XXX"
,
"bogus"
,
url
.
URL
{},
""
,
false
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
...
@@ -80,7 +80,7 @@ func TestSessionManagerGetSessionInStateNoExist(t *testing.T) {
...
@@ -80,7 +80,7 @@ func TestSessionManagerGetSessionInStateNoExist(t *testing.T) {
func
TestSessionManagerGetSessionInStateWrongState
(
t
*
testing
.
T
)
{
func
TestSessionManagerGetSessionInStateWrongState
(
t
*
testing
.
T
)
{
sm
:=
NewSessionManager
(
NewSessionRepo
(),
NewSessionKeyRepo
())
sm
:=
NewSessionManager
(
NewSessionRepo
(),
NewSessionKeyRepo
())
sessionID
,
err
:=
sm
.
NewSession
(
"connector_id"
,
"XXX"
,
"bogus"
,
url
.
URL
{},
""
,
false
)
sessionID
,
err
:=
sm
.
NewSession
(
"connector_id"
,
"XXX"
,
"bogus"
,
url
.
URL
{},
""
,
false
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
...
@@ -95,7 +95,7 @@ func TestSessionManagerGetSessionInStateWrongState(t *testing.T) {
...
@@ -95,7 +95,7 @@ func TestSessionManagerGetSessionInStateWrongState(t *testing.T) {
func
TestSessionManagerKill
(
t
*
testing
.
T
)
{
func
TestSessionManagerKill
(
t
*
testing
.
T
)
{
sm
:=
NewSessionManager
(
NewSessionRepo
(),
NewSessionKeyRepo
())
sm
:=
NewSessionManager
(
NewSessionRepo
(),
NewSessionKeyRepo
())
sessionID
,
err
:=
sm
.
NewSession
(
"connector_id"
,
"XXX"
,
"bogus"
,
url
.
URL
{},
""
,
false
)
sessionID
,
err
:=
sm
.
NewSession
(
"connector_id"
,
"XXX"
,
"bogus"
,
url
.
URL
{},
""
,
false
,
nil
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
t
.
Fatalf
(
"Unexpected error: %v"
,
err
)
}
}
...
...
session/session.go
View file @
066fd859
...
@@ -48,6 +48,9 @@ type Session struct {
...
@@ -48,6 +48,9 @@ type Session struct {
// Nonce is optionally provided in the initial authorization request, and propogated in such cases to the generated claims.
// Nonce is optionally provided in the initial authorization request, and propogated in such cases to the generated claims.
Nonce
string
Nonce
string
// Scope is the 'scope' field in the authentication request. Example scopes are 'openid', 'email', 'offline', etc.
Scope
[]
string
}
}
// Claims returns a new set of Claims for the current session.
// Claims returns a new set of Claims for the current session.
...
...
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