func (r *clientIdentityRepo) New(id string, meta oidc.ClientMetadata) (*oidc.ClientCredentials, error) { secret, err := pcrypto.RandBytes(maxSecretLength) if err != nil { return nil, err } cim, err := newClientIdentityModel(id, secret, &meta) if err != nil { return nil, err } if err := r.executor(nil).Insert(cim); err != nil { if isAlreadyExistsErr(err) { err = errors.New("client ID already exists") } return nil, err } cc := oidc.ClientCredentials{ ID: id, Secret: base64.URLEncoding.EncodeToString(secret), } return &cc, nil }
func (r *clientIdentityRepo) New(id string, meta oidc.ClientMetadata) (*oidc.ClientCredentials, error) { secret, err := pcrypto.RandBytes(maxSecretLength) if err != nil { return nil, err } cim, err := newClientIdentityModel(id, secret, &meta) if err != nil { return nil, err } if err := r.dbMap.Insert(cim); err != nil { if perr, ok := err.(*pq.Error); ok && perr.Code == pgErrorCodeUniqueViolation { err = errors.New("client ID already exists") } return nil, err } cc := oidc.ClientCredentials{ ID: id, Secret: base64.URLEncoding.EncodeToString(secret), } return &cc, nil }
func (cr *memClientIdentityRepo) New(id string, meta oidc.ClientMetadata) (*oidc.ClientCredentials, error) { if _, ok := cr.idents[id]; ok { return nil, errors.New("client ID already exists") } secret, err := pcrypto.RandBytes(32) if err != nil { return nil, err } cc := oidc.ClientCredentials{ ID: id, Secret: base64.URLEncoding.EncodeToString(secret), } cr.idents[id] = oidc.ClientIdentity{ Metadata: meta, Credentials: cc, } return &cc, nil }
func DefaultSecretGenerator() ([]byte, error) { return pcrypto.RandBytes(maxSecretLength) }