remove utils deps
This commit is contained in:
parent
616b42e525
commit
eb774003d7
8 changed files with 46 additions and 88 deletions
|
@ -11,7 +11,7 @@ import (
|
|||
"github.com/gorilla/schema"
|
||||
|
||||
"github.com/caos/oidc/pkg/oidc"
|
||||
str_utils "github.com/caos/utils/strings"
|
||||
"github.com/caos/oidc/pkg/utils"
|
||||
)
|
||||
|
||||
type Authorizer interface {
|
||||
|
@ -94,7 +94,7 @@ func ValidateAuthReqScopes(scopes []string) error {
|
|||
if len(scopes) == 0 {
|
||||
return ErrInvalidRequest("scope missing")
|
||||
}
|
||||
if !str_utils.Contains(scopes, oidc.ScopeOpenID) {
|
||||
if !utils.Contains(scopes, oidc.ScopeOpenID) {
|
||||
return ErrInvalidRequest("scope openid missing")
|
||||
}
|
||||
return nil
|
||||
|
@ -108,7 +108,7 @@ func ValidateAuthReqRedirectURI(uri, client_id string, responseType oidc.Respons
|
|||
if err != nil {
|
||||
return ErrServerError(err.Error())
|
||||
}
|
||||
if !str_utils.Contains(client.RedirectURIs(), uri) {
|
||||
if !utils.Contains(client.RedirectURIs(), uri) {
|
||||
return ErrInvalidRequest("redirect_uri not allowed")
|
||||
}
|
||||
if strings.HasPrefix(uri, "https://") {
|
||||
|
|
12
pkg/op/op.go
12
pkg/op/op.go
|
@ -5,9 +5,9 @@ import (
|
|||
"net/http"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/caos/oidc/pkg/oidc"
|
||||
"github.com/caos/utils/logging"
|
||||
)
|
||||
|
||||
type OpenIDProvider interface {
|
||||
|
@ -36,12 +36,16 @@ func Start(ctx context.Context, o OpenIDProvider) {
|
|||
go func() {
|
||||
<-ctx.Done()
|
||||
err := o.HttpHandler().Shutdown(ctx)
|
||||
logging.Log("SERVE-REqwpM").OnError(err).Error("graceful shutdown of oidc server failed")
|
||||
if err != nil {
|
||||
logrus.Error("graceful shutdown of oidc server failed")
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
err := o.HttpHandler().ListenAndServe()
|
||||
logging.Log("SERVE-4YNIwG").OnError(err).Panic("oidc server serve failed")
|
||||
if err != nil {
|
||||
logrus.Panic("oidc server serve failed")
|
||||
}
|
||||
}()
|
||||
logging.LogWithFields("SERVE-koAFMs", "port", o.Port()).Info("oidc server is listening")
|
||||
logrus.Infof("oidc server is listening on %s", o.Port())
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
"gopkg.in/square/go-jose.v2"
|
||||
|
||||
"github.com/caos/oidc/pkg/oidc"
|
||||
str_utils "github.com/caos/utils/strings"
|
||||
"github.com/caos/oidc/pkg/utils"
|
||||
)
|
||||
|
||||
//DefaultVerifier implements the `Verifier` interface
|
||||
|
@ -126,7 +126,7 @@ type iatConfig struct {
|
|||
//if non of the provided values matches the acr claim
|
||||
func DefaultACRVerifier(possibleValues []string) ACRVerifier {
|
||||
return func(acr string) error {
|
||||
if !str_utils.Contains(possibleValues, acr) {
|
||||
if !utils.Contains(possibleValues, acr) {
|
||||
return ErrAcrInvalid(possibleValues, acr)
|
||||
}
|
||||
return nil
|
||||
|
@ -243,7 +243,7 @@ func (v *DefaultVerifier) checkIssuer(issuer string) error {
|
|||
}
|
||||
|
||||
func (v *DefaultVerifier) checkAudience(audiences []string) error {
|
||||
if !str_utils.Contains(audiences, v.config.clientID) {
|
||||
if !utils.Contains(audiences, v.config.clientID) {
|
||||
return ErrAudienceMissingClientID(v.config.clientID)
|
||||
}
|
||||
|
||||
|
@ -281,7 +281,7 @@ func (v *DefaultVerifier) checkSignature(ctx context.Context, idTokenString stri
|
|||
if len(supportedSigAlgs) == 0 {
|
||||
supportedSigAlgs = []string{"RS256"}
|
||||
}
|
||||
if !str_utils.Contains(supportedSigAlgs, sig.Header.Algorithm) {
|
||||
if !utils.Contains(supportedSigAlgs, sig.Header.Algorithm) {
|
||||
return "", fmt.Errorf("oidc: id token signed with unsupported algorithm, expected %q got %q", supportedSigAlgs, sig.Header.Algorithm)
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/caos/utils/logging"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
func MarshalJSON(w http.ResponseWriter, i interface{}) {
|
||||
|
@ -14,5 +14,7 @@ func MarshalJSON(w http.ResponseWriter, i interface{}) {
|
|||
return
|
||||
}
|
||||
_, err = w.Write(b)
|
||||
logging.Log("UTILS-zVu9OW").OnError(err).Error("error writing response")
|
||||
if err != nil {
|
||||
logrus.Error("error writing response")
|
||||
}
|
||||
}
|
||||
|
|
10
pkg/utils/strings.go
Normal file
10
pkg/utils/strings.go
Normal file
|
@ -0,0 +1,10 @@
|
|||
package utils
|
||||
|
||||
func Contains(list []string, needle string) bool {
|
||||
for _, item := range list {
|
||||
if item == needle {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue