Skip to content

Commit

Permalink
fix linter
Browse files Browse the repository at this point in the history
  • Loading branch information
jkralik committed Jul 1, 2024
1 parent 14507f6 commit e7b4f68
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 26 deletions.
12 changes: 2 additions & 10 deletions cloud2cloud-connector/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,7 @@ func toValidator(c oauth2.Config) validator.Config {

const serviceName = "cloud2cloud-connector"

func newValidator(ctx context.Context, config validator.Config, fileWatcher *fsnotify.Watcher, logger log.Logger, tracerProvider trace.TracerProvider) (*validator.Validator, error) {
v, err := validator.New(ctx, config, fileWatcher, logger, tracerProvider)
if err != nil {
return nil, fmt.Errorf("cannot create validator: %w", err)
}
return v, nil
}

func newAuthInterceptor(ctx context.Context, validator *validator.Validator) kitNetHttp.Interceptor {
func newAuthInterceptor(validator *validator.Validator) kitNetHttp.Interceptor {
authRules := kitNetHttp.NewDefaultAuthorizationRules(uri.API)

whiteList := []kitNetHttp.RequestMatcher{
Expand Down Expand Up @@ -266,7 +258,7 @@ func New(ctx context.Context, config Config, fileWatcher *fsnotify.Watcher, logg

requestHandler := NewRequestHandler(config.APIs.HTTP.Authorization.OwnerClaim, provider, subMgr, store, taskProcessor.Trigger, tracerProvider)

auth := newAuthInterceptor(ctx, validator)
auth := newAuthInterceptor(validator)

httpHandler, err := NewHTTP(requestHandler, auth, logger)
if err != nil {
Expand Down
14 changes: 9 additions & 5 deletions m2m-oauth-server/service/getJWKs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,27 @@ import (
"net/http"
"testing"

"github.com/plgd-dev/hub/v2/m2m-oauth-server/test"
m2mOauthServerTest "github.com/plgd-dev/hub/v2/m2m-oauth-server/test"
"github.com/plgd-dev/hub/v2/m2m-oauth-server/uri"
"github.com/plgd-dev/hub/v2/test/config"
"github.com/plgd-dev/hub/v2/test/oauth-server/test"
"github.com/plgd-dev/kit/v2/codec/json"
"github.com/stretchr/testify/require"
)

func TestRequestHandler_getJWKs(t *testing.T) {
webTearDown := test.SetUp(t)
func TestRequestHandlerGetJWKs(t *testing.T) {
oauthServerTeardown := test.SetUp(t)
defer oauthServerTeardown()

webTearDown := m2mOauthServerTest.SetUp(t)
defer webTearDown()

getJWKs(t)
}

func getJWKs(t *testing.T) map[string]interface{} {
getReq := test.NewRequestBuilder(http.MethodGet, config.M2M_OAUTH_SERVER_HTTP_HOST, uri.JWKs, nil).Build()
res := test.HTTPDo(t, getReq, false)
getReq := m2mOauthServerTest.NewRequestBuilder(http.MethodGet, config.M2M_OAUTH_SERVER_HTTP_HOST, uri.JWKs, nil).Build()
res := m2mOauthServerTest.HTTPDo(t, getReq, false)
defer func() {
_ = res.Body.Close()
}()
Expand Down
4 changes: 2 additions & 2 deletions m2m-oauth-server/service/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ func (requestHandler *RequestHandler) validateTokenRequest(ctx context.Context,
if err := validateClientAssertionType(clientCfg, tokenReq); err != nil {
return err
}
if err := requestHandler.validateClientAssertion(ctx, clientCfg, tokenReq); err != nil {
if err := requestHandler.validateClientAssertion(ctx, tokenReq); err != nil {
return err
}
if err := validateAudience(clientCfg, tokenReq); err != nil {
Expand Down Expand Up @@ -303,7 +303,7 @@ func validateClientAssertionType(clientCfg *Client, tokenReq *tokenRequest) erro
return nil
}

func (requestHandler *RequestHandler) validateClientAssertion(ctx context.Context, clientCfg *Client, tokenReq *tokenRequest) error {
func (requestHandler *RequestHandler) validateClientAssertion(ctx context.Context, tokenReq *tokenRequest) error {
if tokenReq.ClientAssertionType == "" {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/security/oauth2/plgd.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func NewPlgdProvider(ctx context.Context, config Config, fileWatcher *fsnotify.W
config.TokenURL = oidcfg.TokenURL
var p provider
if config.GrantType == oauth.ClientCredentials {
p = NewClientCredentialsPlgdProvider(config, httpClient, oidcfg.JWKSURL, ownerClaim, deviceIDClaim, validator)
p = NewClientCredentialsPlgdProvider(config, httpClient, ownerClaim, deviceIDClaim, validator)
} else {
p = NewAuthCodePlgdProvider(config, httpClient)
}
Expand Down
13 changes: 6 additions & 7 deletions pkg/security/oauth2/plgd_clientCrendetials.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import (

"github.com/plgd-dev/hub/v2/pkg/net/http/client"
"github.com/plgd-dev/hub/v2/pkg/security/jwt"
pkgJwt "github.com/plgd-dev/hub/v2/pkg/security/jwt"
"golang.org/x/oauth2"
)

// NewPlgdProvider creates OAuth client
func NewClientCredentialsPlgdProvider(config Config, httpClient *client.Client, jwksURL string, ownerClaim, deviceIDClaim string, validator *jwt.Validator) *ClientCredentialsPlgdProvider {
func NewClientCredentialsPlgdProvider(config Config, httpClient *client.Client, ownerClaim, deviceIDClaim string, validator *jwt.Validator) *ClientCredentialsPlgdProvider {
return &ClientCredentialsPlgdProvider{
Config: config,
HTTPClient: httpClient,
Expand All @@ -28,22 +27,22 @@ type ClientCredentialsPlgdProvider struct {
HTTPClient *client.Client
ownerClaim string
deviceIDClaim string
jwtValidator *pkgJwt.Validator
jwtValidator *jwt.Validator
}

func (p *ClientCredentialsPlgdProvider) parseToken(ctx context.Context, accessToken string) (pkgJwt.Claims, error) {
func (p *ClientCredentialsPlgdProvider) parseToken(ctx context.Context, accessToken string) (jwt.Claims, error) {
if p.jwtValidator != nil {
claims, err := p.jwtValidator.ParseWithContext(ctx, accessToken)
if err != nil {
return nil, fmt.Errorf("cannot verify authorization code: %w", err)
}
return pkgJwt.Claims(claims), nil
return jwt.Claims(claims), nil
}
claims, err := pkgJwt.ParseToken(accessToken)
claims, err := jwt.ParseToken(accessToken)
if err != nil {
return nil, fmt.Errorf("cannot parse authorization code: %w", err)
}
return pkgJwt.Claims(claims), nil
return claims, nil
}

// Exchange Auth Code for Access Token via OAuth
Expand Down
2 changes: 1 addition & 1 deletion test/oauth-server/service/getJWKs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/stretchr/testify/require"
)

func TestRequestHandler_getJWKs(t *testing.T) {
func TestRequestHandlerGetJWKs(t *testing.T) {
webTearDown := test.SetUp(t)
defer webTearDown()

Expand Down

0 comments on commit e7b4f68

Please sign in to comment.