forked from mystiq/dex
client: generateClientCreds -> addClientCreds
a little easier to read this way IMO.
This commit is contained in:
parent
4440b3a085
commit
86ef34d8e2
1 changed files with 10 additions and 10 deletions
|
@ -77,12 +77,12 @@ 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.generateClientCredentials(c)
|
err := clientManager.addClientCredentials(&c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = clientRepo.New(tx, cli)
|
_, err = clientRepo.New(tx, c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -100,15 +100,15 @@ func (m *ClientManager) New(cli client.Client) (*oidc.ClientCredentials, error)
|
||||||
}
|
}
|
||||||
defer tx.Rollback()
|
defer tx.Rollback()
|
||||||
|
|
||||||
c, err := m.generateClientCredentials(cli)
|
err = m.addClientCredentials(&cli)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
creds := c.Credentials
|
creds := cli.Credentials
|
||||||
|
|
||||||
// Save Client
|
// Save Client
|
||||||
_, err = m.clientRepo.New(tx, c)
|
_, err = m.clientRepo.New(tx, cli)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -189,25 +189,25 @@ func (m *ClientManager) Authenticate(creds oidc.ClientCredentials) (bool, error)
|
||||||
return ok, nil
|
return ok, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m *ClientManager) generateClientCredentials(cli client.Client) (client.Client, error) {
|
func (m *ClientManager) addClientCredentials(cli *client.Client) error {
|
||||||
// Generate Client ID
|
// Generate Client ID
|
||||||
if len(cli.Metadata.RedirectURIs) < 1 {
|
if len(cli.Metadata.RedirectURIs) < 1 {
|
||||||
return cli, errors.New("no client redirect url given")
|
return errors.New("no client redirect url given")
|
||||||
}
|
}
|
||||||
clientID, err := m.clientIDGenerator(cli.Metadata.RedirectURIs[0].Host)
|
clientID, err := m.clientIDGenerator(cli.Metadata.RedirectURIs[0].Host)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Generate Secret
|
// Generate Secret
|
||||||
secret, err := m.secretGenerator()
|
secret, err := m.secretGenerator()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return cli, err
|
return err
|
||||||
}
|
}
|
||||||
clientSecret := base64.URLEncoding.EncodeToString(secret)
|
clientSecret := base64.URLEncoding.EncodeToString(secret)
|
||||||
cli.Credentials = oidc.ClientCredentials{
|
cli.Credentials = oidc.ClientCredentials{
|
||||||
ID: clientID,
|
ID: clientID,
|
||||||
Secret: clientSecret,
|
Secret: clientSecret,
|
||||||
}
|
}
|
||||||
return cli, nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue