2015-08-18 05:57:27 +05:30
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/coreos/dex/client"
|
|
|
|
"github.com/coreos/dex/connector"
|
|
|
|
"github.com/coreos/dex/db"
|
|
|
|
"github.com/coreos/go-oidc/oidc"
|
|
|
|
)
|
|
|
|
|
|
|
|
func newDBDriver(dsn string) (driver, error) {
|
|
|
|
dbc, err := db.NewConnection(db.Config{DSN: dsn})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
drv := &dbDriver{
|
2016-04-15 04:57:57 +05:30
|
|
|
ciRepo: db.NewClientRepo(dbc),
|
2015-08-18 05:57:27 +05:30
|
|
|
cfgRepo: db.NewConnectorConfigRepo(dbc),
|
|
|
|
}
|
|
|
|
|
|
|
|
return drv, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type dbDriver struct {
|
2016-04-15 04:57:57 +05:30
|
|
|
ciRepo client.ClientRepo
|
2015-08-18 05:57:27 +05:30
|
|
|
cfgRepo *db.ConnectorConfigRepo
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *dbDriver) NewClient(meta oidc.ClientMetadata) (*oidc.ClientCredentials, error) {
|
|
|
|
if err := meta.Valid(); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-01-13 06:46:28 +05:30
|
|
|
clientID, err := oidc.GenClientID(meta.RedirectURIs[0].Host)
|
2015-08-18 05:57:27 +05:30
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2016-04-05 23:59:58 +05:30
|
|
|
return d.ciRepo.New(clientID, meta, false)
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func (d *dbDriver) ConnectorConfigs() ([]connector.ConnectorConfig, error) {
|
|
|
|
return d.cfgRepo.All()
|
|
|
|
}
|
|
|
|
|
|
|
|
func (d *dbDriver) SetConnectorConfigs(cfgs []connector.ConnectorConfig) error {
|
|
|
|
return d.cfgRepo.Set(cfgs)
|
|
|
|
}
|