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
73d9742c
Commit
73d9742c
authored
May 20, 2016
by
Evan Cordell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
client manager: accept full client when creating
parent
a418e1c4
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
39 additions
and
27 deletions
+39
-27
api.go
admin/api.go
+1
-1
manager.go
client/manager/manager.go
+14
-18
manager_test.go
client/manager/manager_test.go
+4
-2
driver_db.go
cmd/dexctl/driver_db.go
+5
-1
db_test.go
functional/db_test.go
+4
-2
auth_middleware_test.go
server/auth_middleware_test.go
+5
-1
client_registration.go
server/client_registration.go
+5
-1
client_resource.go
server/client_resource.go
+1
-1
No files found.
admin/api.go
View file @
73d9742c
...
@@ -138,7 +138,7 @@ func (a *AdminAPI) CreateClient(req adminschema.ClientCreateRequest) (adminschem
...
@@ -138,7 +138,7 @@ func (a *AdminAPI) CreateClient(req adminschema.ClientCreateRequest) (adminschem
}
}
// metadata is guaranteed to have at least one redirect_uri by earlier validation.
// metadata is guaranteed to have at least one redirect_uri by earlier validation.
creds
,
err
:=
a
.
clientManager
.
New
(
cli
.
Metadata
)
creds
,
err
:=
a
.
clientManager
.
New
(
cli
)
if
err
!=
nil
{
if
err
!=
nil
{
return
adminschema
.
ClientCreateResponse
{},
mapError
(
err
)
return
adminschema
.
ClientCreateResponse
{},
mapError
(
err
)
}
}
...
...
client/manager/manager.go
View file @
73d9742c
...
@@ -77,11 +77,10 @@ func NewClientManagerFromClients(clientRepo client.ClientRepo, txnFactory repo.T
...
@@ -77,11 +77,10 @@ func NewClientManagerFromClients(clientRepo client.ClientRepo, txnFactory repo.T
return
nil
,
fmt
.
Errorf
(
"client %q has no secret"
,
c
.
Credentials
.
ID
)
return
nil
,
fmt
.
Errorf
(
"client %q has no secret"
,
c
.
Credentials
.
ID
)
}
}
cli
,
err
:=
clientManager
.
clientFromMetadata
(
c
.
Metadata
)
cli
,
err
:=
clientManager
.
generateClientCredentials
(
c
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
cli
.
Admin
=
c
.
Admin
_
,
err
=
clientRepo
.
New
(
tx
,
cli
)
_
,
err
=
clientRepo
.
New
(
tx
,
cli
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -94,22 +93,22 @@ func NewClientManagerFromClients(clientRepo client.ClientRepo, txnFactory repo.T
...
@@ -94,22 +93,22 @@ func NewClientManagerFromClients(clientRepo client.ClientRepo, txnFactory repo.T
return
clientManager
,
nil
return
clientManager
,
nil
}
}
func
(
m
*
ClientManager
)
New
(
meta
oidc
.
ClientMetadata
)
(
*
oidc
.
ClientCredentials
,
error
)
{
func
(
m
*
ClientManager
)
New
(
cli
client
.
Client
)
(
*
oidc
.
ClientCredentials
,
error
)
{
tx
,
err
:=
m
.
begin
()
tx
,
err
:=
m
.
begin
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
defer
tx
.
Rollback
()
defer
tx
.
Rollback
()
c
li
,
err
:=
m
.
clientFromMetadata
(
meta
)
c
,
err
:=
m
.
generateClientCredentials
(
cli
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
creds
:=
c
li
.
Credentials
creds
:=
c
.
Credentials
// Save Client
// Save Client
_
,
err
=
m
.
clientRepo
.
New
(
tx
,
c
li
)
_
,
err
=
m
.
clientRepo
.
New
(
tx
,
c
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -190,28 +189,25 @@ func (m *ClientManager) Authenticate(creds oidc.ClientCredentials) (bool, error)
...
@@ -190,28 +189,25 @@ func (m *ClientManager) Authenticate(creds oidc.ClientCredentials) (bool, error)
return
ok
,
nil
return
ok
,
nil
}
}
func
(
m
*
ClientManager
)
clientFromMetadata
(
meta
oidc
.
ClientMetadata
)
(
client
.
Client
,
error
)
{
func
(
m
*
ClientManager
)
generateClientCredentials
(
cli
client
.
Client
)
(
client
.
Client
,
error
)
{
// Generate Client ID
// Generate Client ID
if
len
(
me
ta
.
RedirectURIs
)
<
1
{
if
len
(
cli
.
Metada
ta
.
RedirectURIs
)
<
1
{
return
cli
ent
.
Client
{}
,
errors
.
New
(
"no client redirect url given"
)
return
cli
,
errors
.
New
(
"no client redirect url given"
)
}
}
clientID
,
err
:=
m
.
clientIDGenerator
(
me
ta
.
RedirectURIs
[
0
]
.
Host
)
clientID
,
err
:=
m
.
clientIDGenerator
(
cli
.
Metada
ta
.
RedirectURIs
[
0
]
.
Host
)
if
err
!=
nil
{
if
err
!=
nil
{
return
cli
ent
.
Client
{}
,
err
return
cli
,
err
}
}
// Generate Secret
// Generate Secret
secret
,
err
:=
m
.
secretGenerator
()
secret
,
err
:=
m
.
secretGenerator
()
if
err
!=
nil
{
if
err
!=
nil
{
return
cli
ent
.
Client
{}
,
err
return
cli
,
err
}
}
clientSecret
:=
base64
.
URLEncoding
.
EncodeToString
(
secret
)
clientSecret
:=
base64
.
URLEncoding
.
EncodeToString
(
secret
)
cli
:=
client
.
Client
{
cli
.
Credentials
=
oidc
.
ClientCredentials
{
Credentials
:
oidc
.
ClientCredentials
{
ID
:
clientID
,
ID
:
clientID
,
Secret
:
clientSecret
,
Secret
:
clientSecret
,
},
Metadata
:
meta
,
}
}
return
cli
,
nil
return
cli
,
nil
}
}
client/manager/manager_test.go
View file @
73d9742c
...
@@ -126,8 +126,10 @@ func TestAuthenticate(t *testing.T) {
...
@@ -126,8 +126,10 @@ func TestAuthenticate(t *testing.T) {
url
.
URL
{
Scheme
:
"http"
,
Host
:
"example.com"
,
Path
:
"/cb"
},
url
.
URL
{
Scheme
:
"http"
,
Host
:
"example.com"
,
Path
:
"/cb"
},
},
},
}
}
cli
:=
client
.
Client
{
cc
,
err
:=
f
.
mgr
.
New
(
cm
)
Metadata
:
cm
,
}
cc
,
err
:=
f
.
mgr
.
New
(
cli
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
err
.
Error
())
t
.
Fatalf
(
err
.
Error
())
}
}
...
...
cmd/dexctl/driver_db.go
View file @
73d9742c
package
main
package
main
import
(
import
(
"github.com/coreos/dex/client"
"github.com/coreos/dex/client/manager"
"github.com/coreos/dex/client/manager"
"github.com/coreos/dex/connector"
"github.com/coreos/dex/connector"
"github.com/coreos/dex/db"
"github.com/coreos/dex/db"
...
@@ -30,7 +31,10 @@ func (d *dbDriver) NewClient(meta oidc.ClientMetadata) (*oidc.ClientCredentials,
...
@@ -30,7 +31,10 @@ func (d *dbDriver) NewClient(meta oidc.ClientMetadata) (*oidc.ClientCredentials,
if
err
:=
meta
.
Valid
();
err
!=
nil
{
if
err
:=
meta
.
Valid
();
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
return
d
.
ciManager
.
New
(
meta
)
cli
:=
client
.
Client
{
Metadata
:
meta
,
}
return
d
.
ciManager
.
New
(
cli
)
}
}
func
(
d
*
dbDriver
)
ConnectorConfigs
()
([]
connector
.
ConnectorConfig
,
error
)
{
func
(
d
*
dbDriver
)
ConnectorConfigs
()
([]
connector
.
ConnectorConfig
,
error
)
{
...
...
functional/db_test.go
View file @
73d9742c
...
@@ -313,8 +313,10 @@ func TestDBClientRepoAuthenticate(t *testing.T) {
...
@@ -313,8 +313,10 @@ func TestDBClientRepoAuthenticate(t *testing.T) {
url
.
URL
{
Scheme
:
"http"
,
Host
:
"127.0.0.1:5556"
,
Path
:
"/cb"
},
url
.
URL
{
Scheme
:
"http"
,
Host
:
"127.0.0.1:5556"
,
Path
:
"/cb"
},
},
},
}
}
cli
:=
client
.
Client
{
cc
,
err
:=
m
.
New
(
cm
)
Metadata
:
cm
,
}
cc
,
err
:=
m
.
New
(
cli
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
err
.
Error
())
t
.
Fatalf
(
err
.
Error
())
}
}
...
...
server/auth_middleware_test.go
View file @
73d9742c
...
@@ -8,6 +8,7 @@ import (
...
@@ -8,6 +8,7 @@ import (
"testing"
"testing"
"time"
"time"
"github.com/coreos/dex/client"
clientmanager
"github.com/coreos/dex/client/manager"
clientmanager
"github.com/coreos/dex/client/manager"
"github.com/coreos/dex/db"
"github.com/coreos/dex/db"
"github.com/coreos/go-oidc/jose"
"github.com/coreos/go-oidc/jose"
...
@@ -33,7 +34,10 @@ func TestClientToken(t *testing.T) {
...
@@ -33,7 +34,10 @@ func TestClientToken(t *testing.T) {
dbm
:=
db
.
NewMemDB
()
dbm
:=
db
.
NewMemDB
()
clientRepo
:=
db
.
NewClientRepo
(
dbm
)
clientRepo
:=
db
.
NewClientRepo
(
dbm
)
clientManager
:=
clientmanager
.
NewClientManager
(
clientRepo
,
db
.
TransactionFactory
(
dbm
),
clientmanager
.
ManagerOptions
{})
clientManager
:=
clientmanager
.
NewClientManager
(
clientRepo
,
db
.
TransactionFactory
(
dbm
),
clientmanager
.
ManagerOptions
{})
creds
,
err
:=
clientManager
.
New
(
clientMetadata
)
cli
:=
client
.
Client
{
Metadata
:
clientMetadata
,
}
creds
,
err
:=
clientManager
.
New
(
cli
)
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Fatalf
(
"Failed to create client: %v"
,
err
)
t
.
Fatalf
(
"Failed to create client: %v"
,
err
)
}
}
...
...
server/client_registration.go
View file @
73d9742c
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"encoding/json"
"encoding/json"
"net/http"
"net/http"
"github.com/coreos/dex/client"
"github.com/coreos/dex/pkg/log"
"github.com/coreos/dex/pkg/log"
"github.com/coreos/go-oidc/oauth2"
"github.com/coreos/go-oidc/oauth2"
...
@@ -38,7 +39,10 @@ func (s *Server) handleClientRegistrationRequest(r *http.Request) (*oidc.ClientR
...
@@ -38,7 +39,10 @@ func (s *Server) handleClientRegistrationRequest(r *http.Request) (*oidc.ClientR
}
}
// metadata is guarenteed to have at least one redirect_uri by earlier validation.
// metadata is guarenteed to have at least one redirect_uri by earlier validation.
creds
,
err
:=
s
.
ClientManager
.
New
(
clientMetadata
)
cli
:=
client
.
Client
{
Metadata
:
clientMetadata
,
}
creds
,
err
:=
s
.
ClientManager
.
New
(
cli
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Errorf
(
"Failed to create new client identity: %v"
,
err
)
log
.
Errorf
(
"Failed to create new client identity: %v"
,
err
)
return
nil
,
newAPIError
(
oauth2
.
ErrorServerError
,
"unable to save client metadata"
)
return
nil
,
newAPIError
(
oauth2
.
ErrorServerError
,
"unable to save client metadata"
)
...
...
server/client_resource.go
View file @
73d9742c
...
@@ -87,7 +87,7 @@ func (c *clientResource) create(w http.ResponseWriter, r *http.Request) {
...
@@ -87,7 +87,7 @@ func (c *clientResource) create(w http.ResponseWriter, r *http.Request) {
writeAPIError
(
w
,
http
.
StatusBadRequest
,
newAPIError
(
errorInvalidClientMetadata
,
err
.
Error
()))
writeAPIError
(
w
,
http
.
StatusBadRequest
,
newAPIError
(
errorInvalidClientMetadata
,
err
.
Error
()))
return
return
}
}
creds
,
err
:=
c
.
manager
.
New
(
ci
.
Metadata
)
creds
,
err
:=
c
.
manager
.
New
(
ci
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Errorf
(
"Failed creating client: %v"
,
err
)
log
.
Errorf
(
"Failed creating client: %v"
,
err
)
...
...
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