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/schema/workerschema/mapper.go
Eric Chiang 5e44b6bc27 *: update all to accommodate changes to go-oidc
Update dex to comply with the changes to fieldnames and types of
the client and provider metadata structs in coreos/go-oidc.
2016-01-12 17:16:28 -08:00

57 lines
1.2 KiB
Go

package workerschema
import (
"errors"
"net/url"
"github.com/coreos/go-oidc/oidc"
)
func MapSchemaClientToClientIdentity(sc Client) (oidc.ClientIdentity, error) {
ci := oidc.ClientIdentity{
Credentials: oidc.ClientCredentials{
ID: sc.Id,
},
Metadata: oidc.ClientMetadata{
RedirectURIs: make([]url.URL, len(sc.RedirectURIs)),
},
}
for i, ru := range sc.RedirectURIs {
if ru == "" {
return oidc.ClientIdentity{}, errors.New("redirect URL empty")
}
u, err := url.Parse(ru)
if err != nil {
return oidc.ClientIdentity{}, errors.New("redirect URL invalid")
}
ci.Metadata.RedirectURIs[i] = *u
}
return ci, nil
}
func MapClientIdentityToSchemaClient(c oidc.ClientIdentity) Client {
cl := Client{
Id: c.Credentials.ID,
RedirectURIs: make([]string, len(c.Metadata.RedirectURIs)),
}
for i, u := range c.Metadata.RedirectURIs {
cl.RedirectURIs[i] = u.String()
}
return cl
}
func MapClientIdentityToSchemaClientWithSecret(c oidc.ClientIdentity) ClientWithSecret {
cl := ClientWithSecret{
Id: c.Credentials.ID,
Secret: c.Credentials.Secret,
RedirectURIs: make([]string, len(c.Metadata.RedirectURIs)),
}
for i, u := range c.Metadata.RedirectURIs {
cl.RedirectURIs[i] = u.String()
}
return cl
}