コード例 #1
0
ファイル: admin_api_test.go プロジェクト: cgenuity/dex
func makeAdminAPITestFixtures() *adminAPITestFixtures {
	f := &adminAPITestFixtures{}

	dbMap, ur, pwr, um := makeUserObjects(adminUsers, adminPasswords)

	var cliCount int
	secGen := func() ([]byte, error) {
		id := []byte(fmt.Sprintf("client_%v", cliCount))
		cliCount++
		return id, nil
	}
	cr := db.NewClientRepo(dbMap)
	clientIDGenerator := func(hostport string) (string, error) {
		return fmt.Sprintf("client_%v", hostport), nil
	}
	cm := manager.NewClientManager(cr, db.TransactionFactory(dbMap), manager.ManagerOptions{SecretGenerator: secGen, ClientIDGenerator: clientIDGenerator})
	ccr := db.NewConnectorConfigRepo(dbMap)

	f.cr = cr
	f.ur = ur
	f.pwr = pwr
	f.adAPI = admin.NewAdminAPI(ur, pwr, cr, ccr, um, cm, "local")
	f.adSrv = server.NewAdminServer(f.adAPI, nil, adminAPITestSecret)
	f.hSrv = httptest.NewServer(f.adSrv.HTTPHandler())
	f.hc = &http.Client{
		Transport: &adminAPITransport{
			secret: adminAPITestSecret,
		},
	}
	f.adClient, _ = adminschema.NewWithBasePath(f.hc, f.hSrv.URL)

	return f
}
コード例 #2
0
ファイル: admin_api_connector.go プロジェクト: ajanthan/dex
func (d *AdminAPIConnector) NewClient(meta oidc.ClientMetadata) (*oidc.ClientCredentials, error) {
	if err := meta.Valid(); err != nil {
		return nil, err
	}
	cli := client.Client{
		Metadata: meta,
	}
	credential := &oidc.ClientCredentials{}
	service, err := adminschema.NewWithBasePath(d.client, d.baseURL)
	if err != nil {
		return credential, nil
	}
	urls := make([]string, len(cli.Metadata.RedirectURIs))
	for i, url := range cli.Metadata.RedirectURIs {
		urls[i] = url.String()
	}
	c := &adminschema.Client{RedirectURIs: urls}
	createClientRequest := &adminschema.ClientCreateRequest{Client: c}
	response, err := service.Client.Create(createClientRequest).Do()
	if err != nil {
		return credential, err
	}
	credential.ID = response.Client.Id
	credential.Secret = response.Client.Secret
	return credential, nil
}
コード例 #3
0
ファイル: admin_api_connector.go プロジェクト: ajanthan/dex
func (d *AdminAPIConnector) SetConnectorConfigs(cfgs []interface{}) error {
	service, err := adminschema.NewWithBasePath(d.client, d.baseURL)
	if err != nil {
		return nil
	}
	connectorAddRequest := &adminschema.ConnectorsSetRequest{Connectors: cfgs}
	if err := service.Connectors.Set(connectorAddRequest).Do(); err != nil {
		return err
	}
	return nil
}
コード例 #4
0
ファイル: admin_api_connector.go プロジェクト: ajanthan/dex
func (d *AdminAPIConnector) ConnectorConfigs() ([]interface{}, error) {
	var connectors []interface{}
	service, err := adminschema.NewWithBasePath(d.client, d.baseURL)
	if err != nil {
		return connectors, nil
	}
	response, err := service.Connectors.Get().Do()
	if err != nil {
		return connectors, err
	}
	connectors = response.Connectors
	return connectors, nil
}
コード例 #5
0
ファイル: admin_api_test.go プロジェクト: no2key/dex
func makeAdminAPITestFixtures() *adminAPITestFixtures {
	f := &adminAPITestFixtures{}

	ur, pwr, um := makeUserObjects(adminUsers, adminPasswords)
	f.ur = ur
	f.pwr = pwr
	f.adAPI = admin.NewAdminAPI(um, f.ur, f.pwr, "local")
	f.adSrv = server.NewAdminServer(f.adAPI, nil)
	f.hSrv = httptest.NewServer(f.adSrv.HTTPHandler())
	f.hc = &http.Client{}
	f.adClient, _ = adminschema.NewWithBasePath(f.hc, f.hSrv.URL)

	return f
}