2015-08-18 05:57:27 +05:30
|
|
|
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{
|
2016-01-13 06:46:28 +05:30
|
|
|
RedirectURIs: make([]url.URL, len(sc.RedirectURIs)),
|
2015-08-18 05:57:27 +05:30
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
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")
|
|
|
|
}
|
|
|
|
|
2016-01-13 06:46:28 +05:30
|
|
|
ci.Metadata.RedirectURIs[i] = *u
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
return ci, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func MapClientIdentityToSchemaClient(c oidc.ClientIdentity) Client {
|
|
|
|
cl := Client{
|
|
|
|
Id: c.Credentials.ID,
|
2016-01-13 06:46:28 +05:30
|
|
|
RedirectURIs: make([]string, len(c.Metadata.RedirectURIs)),
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
2016-01-13 06:46:28 +05:30
|
|
|
for i, u := range c.Metadata.RedirectURIs {
|
2015-08-18 05:57:27 +05:30
|
|
|
cl.RedirectURIs[i] = u.String()
|
|
|
|
}
|
|
|
|
return cl
|
|
|
|
}
|
|
|
|
|
|
|
|
func MapClientIdentityToSchemaClientWithSecret(c oidc.ClientIdentity) ClientWithSecret {
|
|
|
|
cl := ClientWithSecret{
|
|
|
|
Id: c.Credentials.ID,
|
|
|
|
Secret: c.Credentials.Secret,
|
2016-01-13 06:46:28 +05:30
|
|
|
RedirectURIs: make([]string, len(c.Metadata.RedirectURIs)),
|
2015-08-18 05:57:27 +05:30
|
|
|
}
|
2016-01-13 06:46:28 +05:30
|
|
|
for i, u := range c.Metadata.RedirectURIs {
|
2015-08-18 05:57:27 +05:30
|
|
|
cl.RedirectURIs[i] = u.String()
|
|
|
|
}
|
|
|
|
return cl
|
|
|
|
}
|