This repository has been archived on 2022-08-17. You can view files and clone it, but cannot push or open issues or pull requests.
dex/cmd/dexctl/driver_api.go

72 lines
1.6 KiB
Go
Raw Normal View History

2015-08-18 05:57:27 +05:30
package main
import (
"errors"
"net/http"
"github.com/coreos/dex/connector"
schema "github.com/coreos/dex/schema/workerschema"
"github.com/coreos/go-oidc/oidc"
)
func newAPIDriver(pcfg oidc.ProviderConfig, creds oidc.ClientCredentials) (driver, error) {
ccfg := oidc.ClientConfig{
ProviderConfig: pcfg,
Credentials: creds,
}
oc, err := oidc.NewClient(ccfg)
if err != nil {
return nil, err
}
trans := &oidc.AuthenticatedTransport{
TokenRefresher: &oidc.ClientCredsTokenRefresher{
Issuer: pcfg.Issuer.String(),
2015-08-18 05:57:27 +05:30
OIDCClient: oc,
},
RoundTripper: http.DefaultTransport,
}
hc := &http.Client{Transport: trans}
svc, err := schema.NewWithBasePath(hc, pcfg.Issuer.String())
2015-08-18 05:57:27 +05:30
if err != nil {
return nil, err
}
return &apiDriver{svc: svc}, nil
}
type apiDriver struct {
svc *schema.Service
}
func (d *apiDriver) NewClient(meta oidc.ClientMetadata) (*oidc.ClientCredentials, error) {
sc := &schema.Client{
RedirectURIs: make([]string, len(meta.RedirectURIs)),
2015-08-18 05:57:27 +05:30
}
for i, u := range meta.RedirectURIs {
2015-08-18 05:57:27 +05:30
sc.RedirectURIs[i] = u.String()
}
call := d.svc.Clients.Create(sc)
scs, err := call.Do()
if err != nil {
return nil, err
}
creds := &oidc.ClientCredentials{
ID: scs.Id,
Secret: scs.Secret,
}
return creds, nil
}
func (d *apiDriver) ConnectorConfigs() ([]connector.ConnectorConfig, error) {
return nil, errors.New("unable to get connector configs from HTTP API")
}
func (d *apiDriver) SetConnectorConfigs(cfgs []connector.ConnectorConfig) error {
return errors.New("unable to set connector configs through HTTP API")
}