🚨 Fixed linters warnings
This commit is contained in:
parent
289fb8987d
commit
5d311b5c8d
|
@ -12,14 +12,20 @@ output:
|
||||||
sort-results: true
|
sort-results: true
|
||||||
linters-settings:
|
linters-settings:
|
||||||
gci:
|
gci:
|
||||||
local-prefixes: source.toby3d.me
|
sections:
|
||||||
|
- standard
|
||||||
|
- default
|
||||||
|
- prefix(source.toby3d.me)
|
||||||
|
section-separators:
|
||||||
|
- newLine
|
||||||
goimports:
|
goimports:
|
||||||
local-prefixes: source.toby3d.me
|
local-prefixes: source.toby3d.me
|
||||||
ireturn:
|
ireturn:
|
||||||
allow:
|
allow:
|
||||||
- "(Repository|UseCase)$"
|
|
||||||
- error
|
- error
|
||||||
- stdlib
|
- stdlib
|
||||||
|
- "(Repository|UseCase)$"
|
||||||
|
- "sqlmock.Sqlmock"
|
||||||
lll:
|
lll:
|
||||||
tab-width: 8
|
tab-width: 8
|
||||||
varnamelen:
|
varnamelen:
|
||||||
|
@ -31,7 +37,9 @@ linters-settings:
|
||||||
- db # dataBase
|
- db # dataBase
|
||||||
- err # error
|
- err # error
|
||||||
- i # index
|
- i # index
|
||||||
|
- id
|
||||||
- ip
|
- ip
|
||||||
|
- j # alt index
|
||||||
- ln # listener
|
- ln # listener
|
||||||
- me
|
- me
|
||||||
- ok
|
- ok
|
||||||
|
|
|
@ -13,14 +13,14 @@ import (
|
||||||
"golang.org/x/text/language"
|
"golang.org/x/text/language"
|
||||||
"golang.org/x/text/message"
|
"golang.org/x/text/message"
|
||||||
|
|
||||||
"source.toby3d.me/toby3d/form"
|
|
||||||
"source.toby3d.me/toby3d/middleware"
|
|
||||||
"source.toby3d.me/toby3d/auth/internal/auth"
|
"source.toby3d.me/toby3d/auth/internal/auth"
|
||||||
"source.toby3d.me/toby3d/auth/internal/client"
|
"source.toby3d.me/toby3d/auth/internal/client"
|
||||||
"source.toby3d.me/toby3d/auth/internal/common"
|
"source.toby3d.me/toby3d/auth/internal/common"
|
||||||
"source.toby3d.me/toby3d/auth/internal/domain"
|
"source.toby3d.me/toby3d/auth/internal/domain"
|
||||||
"source.toby3d.me/toby3d/auth/internal/profile"
|
"source.toby3d.me/toby3d/auth/internal/profile"
|
||||||
"source.toby3d.me/toby3d/auth/web"
|
"source.toby3d.me/toby3d/auth/web"
|
||||||
|
"source.toby3d.me/toby3d/form"
|
||||||
|
"source.toby3d.me/toby3d/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
@ -349,6 +349,7 @@ func NewAuthAuthorizationRequest() *AuthAuthorizationRequest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint: cyclop
|
||||||
func (r *AuthAuthorizationRequest) bind(ctx *http.RequestCtx) error {
|
func (r *AuthAuthorizationRequest) bind(ctx *http.RequestCtx) error {
|
||||||
indieAuthError := new(domain.Error)
|
indieAuthError := new(domain.Error)
|
||||||
if err := form.Unmarshal(ctx.QueryArgs(), r); err != nil {
|
if err := form.Unmarshal(ctx.QueryArgs(), r); err != nil {
|
||||||
|
@ -424,7 +425,7 @@ func NewAuthVerifyRequest() *AuthVerifyRequest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint: funlen
|
//nolint: funlen,cyclop
|
||||||
func (r *AuthVerifyRequest) bind(ctx *http.RequestCtx) error {
|
func (r *AuthVerifyRequest) bind(ctx *http.RequestCtx) error {
|
||||||
indieAuthError := new(domain.Error)
|
indieAuthError := new(domain.Error)
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,8 @@ func TestAuthorize(t *testing.T) {
|
||||||
deps.store.Store(path.Join(profilerepo.DefaultPathPrefix, me.String()), user.Profile)
|
deps.store.Store(path.Join(profilerepo.DefaultPathPrefix, me.String()), user.Profile)
|
||||||
deps.store.Store(path.Join(userrepo.DefaultPathPrefix, me.String()), user)
|
deps.store.Store(path.Join(userrepo.DefaultPathPrefix, me.String()), user)
|
||||||
|
|
||||||
r := router.New() //nolint: varnamelen
|
r := router.New()
|
||||||
|
//nolint: exhaustivestruct
|
||||||
delivery.NewRequestHandler(delivery.NewRequestHandlerOptions{
|
delivery.NewRequestHandler(delivery.NewRequestHandlerOptions{
|
||||||
Auth: deps.authService,
|
Auth: deps.authService,
|
||||||
Clients: deps.clientService,
|
Clients: deps.clientService,
|
||||||
|
|
|
@ -87,6 +87,7 @@ func (h *RequestHandler) handleRender(ctx *http.RequestCtx) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint: funlen
|
||||||
func (h *RequestHandler) handleCallback(ctx *http.RequestCtx) {
|
func (h *RequestHandler) handleCallback(ctx *http.RequestCtx) {
|
||||||
ctx.SetContentType(common.MIMETextHTMLCharsetUTF8)
|
ctx.SetContentType(common.MIMETextHTMLCharsetUTF8)
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ func TestRead(t *testing.T) {
|
||||||
|
|
||||||
deps := NewDependencies(t)
|
deps := NewDependencies(t)
|
||||||
|
|
||||||
r := router.New() //nolint: varnamelen
|
r := router.New()
|
||||||
delivery.NewRequestHandler(delivery.NewRequestHandlerOptions{
|
delivery.NewRequestHandler(delivery.NewRequestHandlerOptions{
|
||||||
Client: deps.client,
|
Client: deps.client,
|
||||||
Config: deps.config,
|
Config: deps.config,
|
||||||
|
|
|
@ -127,12 +127,12 @@ func (ccm CodeChallengeMethod) Validate(codeChallenge, verifier string) bool {
|
||||||
return codeChallenge == verifier
|
return codeChallenge == verifier
|
||||||
}
|
}
|
||||||
|
|
||||||
h := ccm.hash
|
hash := ccm.hash
|
||||||
h.Reset() // WARN(toby3d): even hash.New contains something.
|
hash.Reset() // WARN(toby3d): even hash.New contains something.
|
||||||
|
|
||||||
if _, err := h.Write([]byte(verifier)); err != nil {
|
if _, err := hash.Write([]byte(verifier)); err != nil {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return codeChallenge == base64.RawURLEncoding.EncodeToString(h.Sum(nil))
|
return codeChallenge == base64.RawURLEncoding.EncodeToString(hash.Sum(nil))
|
||||||
}
|
}
|
||||||
|
|
|
@ -144,14 +144,14 @@ func TestCodeChallengeMethod_Validate(t *testing.T) {
|
||||||
case domain.CodeChallengeMethodUndefined, domain.CodeChallengeMethodPLAIN:
|
case domain.CodeChallengeMethodUndefined, domain.CodeChallengeMethodPLAIN:
|
||||||
codeChallenge = verifier
|
codeChallenge = verifier
|
||||||
default:
|
default:
|
||||||
h := tc.hash
|
hash := tc.hash
|
||||||
h.Reset()
|
hash.Reset()
|
||||||
|
|
||||||
if _, err := h.Write([]byte(verifier)); err != nil {
|
if _, err := hash.Write([]byte(verifier)); err != nil {
|
||||||
t.Error(err)
|
t.Error(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
codeChallenge = base64.RawURLEncoding.EncodeToString(h.Sum(nil))
|
codeChallenge = base64.RawURLEncoding.EncodeToString(hash.Sum(nil))
|
||||||
}
|
}
|
||||||
|
|
||||||
if result := tc.in.Validate(codeChallenge, verifier); result != !tc.expError {
|
if result := tc.in.Validate(codeChallenge, verifier); result != !tc.expError {
|
||||||
|
@ -169,7 +169,7 @@ func TestCodeChallengeMethod_Validate_IndieAuth(t *testing.T) {
|
||||||
"6f535c952339f0670311b4bbec5c41c00805e83291fc7eb15ca4963f82a4d57595787dcc6ee90571fb7789cbd521fe0178ed",
|
"6f535c952339f0670311b4bbec5c41c00805e83291fc7eb15ca4963f82a4d57595787dcc6ee90571fb7789cbd521fe0178ed",
|
||||||
); !ok {
|
); !ok {
|
||||||
t.Errorf("Validate(%s, %s) = %t, want %t", "ALiMNf5FvF_LIWLhSkd9tjPKh3PEmai2OrdDBzrVZ3M",
|
t.Errorf("Validate(%s, %s) = %t, want %t", "ALiMNf5FvF_LIWLhSkd9tjPKh3PEmai2OrdDBzrVZ3M",
|
||||||
"6f535c952339f0670311b4bbec5c41c00805e83291fc7eb15ca4963f82a4d57595787dcc6ee90571fb7789cbd521fe0178ed", ok, true,
|
"6f535c952339f0670311b4bbec5c41c00805e83291fc7eb15ca4963f82a4d57595787dcc6ee90571fb7789cbd521"+
|
||||||
)
|
"fe0178ed", ok, true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ var DefaultNewTokenOptions = NewTokenOptions{
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewToken create a new token by provided options.
|
// NewToken create a new token by provided options.
|
||||||
//nolint: funlen,cyclop
|
//nolint: cyclop
|
||||||
func NewToken(opts NewTokenOptions) (*Token, error) {
|
func NewToken(opts NewTokenOptions) (*Token, error) {
|
||||||
if opts.NonceLength == 0 {
|
if opts.NonceLength == 0 {
|
||||||
opts.NonceLength = DefaultNewTokenOptions.NonceLength
|
opts.NonceLength = DefaultNewTokenOptions.NonceLength
|
||||||
|
|
|
@ -4,8 +4,8 @@ import (
|
||||||
"github.com/fasthttp/router"
|
"github.com/fasthttp/router"
|
||||||
http "github.com/valyala/fasthttp"
|
http "github.com/valyala/fasthttp"
|
||||||
|
|
||||||
"source.toby3d.me/toby3d/middleware"
|
|
||||||
"source.toby3d.me/toby3d/auth/internal/common"
|
"source.toby3d.me/toby3d/auth/internal/common"
|
||||||
|
"source.toby3d.me/toby3d/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
type RequestHandler struct{}
|
type RequestHandler struct{}
|
||||||
|
|
|
@ -5,9 +5,9 @@ import (
|
||||||
"github.com/goccy/go-json"
|
"github.com/goccy/go-json"
|
||||||
http "github.com/valyala/fasthttp"
|
http "github.com/valyala/fasthttp"
|
||||||
|
|
||||||
"source.toby3d.me/toby3d/middleware"
|
|
||||||
"source.toby3d.me/toby3d/auth/internal/common"
|
"source.toby3d.me/toby3d/auth/internal/common"
|
||||||
"source.toby3d.me/toby3d/auth/internal/domain"
|
"source.toby3d.me/toby3d/auth/internal/domain"
|
||||||
|
"source.toby3d.me/toby3d/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
|
|
@ -72,6 +72,7 @@ func (repo *httpMetadataRepository) Get(ctx context.Context, me *domain.Me) (*do
|
||||||
return nil, fmt.Errorf("cannot unmarshal metadata configuration: %w", err)
|
return nil, fmt.Errorf("cannot unmarshal metadata configuration: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint: exhaustivestruct // TODO(toby3d)
|
||||||
return &domain.Metadata{
|
return &domain.Metadata{
|
||||||
AuthorizationEndpoint: data.AuthorizationEndpoint,
|
AuthorizationEndpoint: data.AuthorizationEndpoint,
|
||||||
AuthorizationResponseIssParameterSupported: data.AuthorizationResponseIssParameterSupported,
|
AuthorizationResponseIssParameterSupported: data.AuthorizationResponseIssParameterSupported,
|
||||||
|
|
|
@ -32,6 +32,7 @@ func NewHTPPClientRepository(client *http.Client) profile.Repository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint: cyclop
|
||||||
func (repo *httpProfileRepository) Get(ctx context.Context, me *domain.Me) (*domain.Profile, error) {
|
func (repo *httpProfileRepository) Get(ctx context.Context, me *domain.Me) (*domain.Profile, error) {
|
||||||
req := http.AcquireRequest()
|
req := http.AcquireRequest()
|
||||||
defer http.ReleaseRequest(req)
|
defer http.ReleaseRequest(req)
|
||||||
|
|
|
@ -3,9 +3,7 @@ package httptest
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
_ "embed" // used for running tests without same import in "god object"
|
||||||
// used for running tests.
|
|
||||||
_ "embed"
|
|
||||||
"net"
|
"net"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
|
|
||||||
"github.com/DATA-DOG/go-sqlmock"
|
"github.com/DATA-DOG/go-sqlmock"
|
||||||
"github.com/jmoiron/sqlx"
|
"github.com/jmoiron/sqlx"
|
||||||
_ "modernc.org/sqlite"
|
_ "modernc.org/sqlite" // used for running tests without same import in "god object"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Time struct{}
|
type Time struct{}
|
||||||
|
|
|
@ -12,13 +12,13 @@ import (
|
||||||
"golang.org/x/text/language"
|
"golang.org/x/text/language"
|
||||||
"golang.org/x/text/message"
|
"golang.org/x/text/message"
|
||||||
|
|
||||||
"source.toby3d.me/toby3d/form"
|
|
||||||
"source.toby3d.me/toby3d/middleware"
|
|
||||||
"source.toby3d.me/toby3d/auth/internal/common"
|
"source.toby3d.me/toby3d/auth/internal/common"
|
||||||
"source.toby3d.me/toby3d/auth/internal/domain"
|
"source.toby3d.me/toby3d/auth/internal/domain"
|
||||||
"source.toby3d.me/toby3d/auth/internal/random"
|
"source.toby3d.me/toby3d/auth/internal/random"
|
||||||
"source.toby3d.me/toby3d/auth/internal/ticket"
|
"source.toby3d.me/toby3d/auth/internal/ticket"
|
||||||
"source.toby3d.me/toby3d/auth/web"
|
"source.toby3d.me/toby3d/auth/web"
|
||||||
|
"source.toby3d.me/toby3d/form"
|
||||||
|
"source.toby3d.me/toby3d/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
@ -57,6 +57,7 @@ func NewRequestHandler(tickets ticket.UseCase, matcher language.Matcher, config
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *RequestHandler) Register(r *router.Router) {
|
func (h *RequestHandler) Register(r *router.Router) {
|
||||||
|
//nolint: exhaustivestruct
|
||||||
chain := middleware.Chain{
|
chain := middleware.Chain{
|
||||||
middleware.CSRFWithConfig(middleware.CSRFConfig{
|
middleware.CSRFWithConfig(middleware.CSRFConfig{
|
||||||
Skipper: func(ctx *http.RequestCtx) bool {
|
Skipper: func(ctx *http.RequestCtx) bool {
|
||||||
|
|
|
@ -79,7 +79,7 @@ func NewDependencies(tb testing.TB) Dependencies {
|
||||||
ticket := domain.TestTicket(tb)
|
ticket := domain.TestTicket(tb)
|
||||||
token := domain.TestToken(tb)
|
token := domain.TestToken(tb)
|
||||||
|
|
||||||
r := router.New() //nolint: varnamelen
|
r := router.New()
|
||||||
// NOTE(toby3d): private resource
|
// NOTE(toby3d): private resource
|
||||||
r.GET(ticket.Resource.URL().EscapedPath(), func(ctx *http.RequestCtx) {
|
r.GET(ticket.Resource.URL().EscapedPath(), func(ctx *http.RequestCtx) {
|
||||||
ctx.SuccessString(common.MIMETextHTMLCharsetUTF8,
|
ctx.SuccessString(common.MIMETextHTMLCharsetUTF8,
|
||||||
|
|
|
@ -9,12 +9,12 @@ import (
|
||||||
"github.com/lestrrat-go/jwx/jwa"
|
"github.com/lestrrat-go/jwx/jwa"
|
||||||
http "github.com/valyala/fasthttp"
|
http "github.com/valyala/fasthttp"
|
||||||
|
|
||||||
"source.toby3d.me/toby3d/form"
|
|
||||||
"source.toby3d.me/toby3d/middleware"
|
|
||||||
"source.toby3d.me/toby3d/auth/internal/common"
|
"source.toby3d.me/toby3d/auth/internal/common"
|
||||||
"source.toby3d.me/toby3d/auth/internal/domain"
|
"source.toby3d.me/toby3d/auth/internal/domain"
|
||||||
"source.toby3d.me/toby3d/auth/internal/ticket"
|
"source.toby3d.me/toby3d/auth/internal/ticket"
|
||||||
"source.toby3d.me/toby3d/auth/internal/token"
|
"source.toby3d.me/toby3d/auth/internal/token"
|
||||||
|
"source.toby3d.me/toby3d/form"
|
||||||
|
"source.toby3d.me/toby3d/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
@ -138,6 +138,7 @@ func NewRequestHandler(tokens token.UseCase, tickets ticket.UseCase, config *dom
|
||||||
|
|
||||||
func (h *RequestHandler) Register(r *router.Router) {
|
func (h *RequestHandler) Register(r *router.Router) {
|
||||||
chain := middleware.Chain{
|
chain := middleware.Chain{
|
||||||
|
//nolint: exhaustivestruct
|
||||||
middleware.JWTWithConfig(middleware.JWTConfig{
|
middleware.JWTWithConfig(middleware.JWTConfig{
|
||||||
AuthScheme: "Bearer",
|
AuthScheme: "Bearer",
|
||||||
ContextKey: "token",
|
ContextKey: "token",
|
||||||
|
@ -227,6 +228,7 @@ func (h *RequestHandler) handleAction(ctx *http.RequestCtx) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint: funlen
|
||||||
func (h *RequestHandler) handleExchange(ctx *http.RequestCtx) {
|
func (h *RequestHandler) handleExchange(ctx *http.RequestCtx) {
|
||||||
ctx.SetContentType(common.MIMEApplicationJSONCharsetUTF8)
|
ctx.SetContentType(common.MIMEApplicationJSONCharsetUTF8)
|
||||||
|
|
||||||
|
|
|
@ -76,9 +76,6 @@ func TestIntrospection(t *testing.T) {
|
||||||
|
|
||||||
result := new(delivery.TokenIntrospectResponse)
|
result := new(delivery.TokenIntrospectResponse)
|
||||||
if err := json.Unmarshal(resp.Body(), result); err != nil {
|
if err := json.Unmarshal(resp.Body(), result); err != nil {
|
||||||
e := err.(*json.SyntaxError)
|
|
||||||
|
|
||||||
t.Logf("%s\noffset: %d", resp.Body(), e.Offset)
|
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -41,8 +41,10 @@ func NewTokenUseCase(config Config) token.UseCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint: cyclop
|
||||||
func (uc *tokenUseCase) Exchange(ctx context.Context, opts token.ExchangeOptions) (*domain.Token, *domain.Profile,
|
func (uc *tokenUseCase) Exchange(ctx context.Context, opts token.ExchangeOptions) (*domain.Token, *domain.Profile,
|
||||||
error) {
|
error,
|
||||||
|
) {
|
||||||
session, err := uc.sessions.GetAndDelete(ctx, opts.Code)
|
session, err := uc.sessions.GetAndDelete(ctx, opts.Code)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, fmt.Errorf("cannot get session from store: %w", err)
|
return nil, nil, fmt.Errorf("cannot get session from store: %w", err)
|
||||||
|
@ -127,7 +129,7 @@ func (uc *tokenUseCase) Verify(ctx context.Context, accessToken string) (*domain
|
||||||
|
|
||||||
profile, err := uc.profiles.Get(ctx, result.Me)
|
profile, err := uc.profiles.Get(ctx, result.Me)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, nil, nil
|
return result, nil, nil //nolint: nilerr // it's okay to return result without profile
|
||||||
}
|
}
|
||||||
|
|
||||||
if !result.Scope.Has(domain.ScopeEmail) && len(profile.Email) > 0 {
|
if !result.Scope.Has(domain.ScopeEmail) && len(profile.Email) > 0 {
|
||||||
|
|
|
@ -8,10 +8,10 @@ import (
|
||||||
"github.com/lestrrat-go/jwx/jwa"
|
"github.com/lestrrat-go/jwx/jwa"
|
||||||
http "github.com/valyala/fasthttp"
|
http "github.com/valyala/fasthttp"
|
||||||
|
|
||||||
"source.toby3d.me/toby3d/middleware"
|
|
||||||
"source.toby3d.me/toby3d/auth/internal/common"
|
"source.toby3d.me/toby3d/auth/internal/common"
|
||||||
"source.toby3d.me/toby3d/auth/internal/domain"
|
"source.toby3d.me/toby3d/auth/internal/domain"
|
||||||
"source.toby3d.me/toby3d/auth/internal/token"
|
"source.toby3d.me/toby3d/auth/internal/token"
|
||||||
|
"source.toby3d.me/toby3d/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
@ -37,6 +37,7 @@ func NewRequestHandler(tokens token.UseCase, config *domain.Config) *RequestHand
|
||||||
|
|
||||||
func (h *RequestHandler) Register(r *router.Router) {
|
func (h *RequestHandler) Register(r *router.Router) {
|
||||||
chain := middleware.Chain{
|
chain := middleware.Chain{
|
||||||
|
//nolint: exhaustivestruct
|
||||||
middleware.JWTWithConfig(middleware.JWTConfig{
|
middleware.JWTWithConfig(middleware.JWTConfig{
|
||||||
AuthScheme: "Bearer",
|
AuthScheme: "Bearer",
|
||||||
ContextKey: "token",
|
ContextKey: "token",
|
||||||
|
@ -62,7 +63,7 @@ func (h *RequestHandler) handleUserInformation(ctx *http.RequestCtx) {
|
||||||
if err != nil || tkn == nil {
|
if err != nil || tkn == nil {
|
||||||
// WARN(toby3d): If the token is not valid, the endpoint still
|
// WARN(toby3d): If the token is not valid, the endpoint still
|
||||||
// MUST return a 200 Response.
|
// MUST return a 200 Response.
|
||||||
_ = encoder.Encode(err)
|
_ = encoder.Encode(err) //nolint: errchkjson
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -70,6 +71,7 @@ func (h *RequestHandler) handleUserInformation(ctx *http.RequestCtx) {
|
||||||
if !tkn.Scope.Has(domain.ScopeProfile) {
|
if !tkn.Scope.Has(domain.ScopeProfile) {
|
||||||
ctx.SetStatusCode(http.StatusForbidden)
|
ctx.SetStatusCode(http.StatusForbidden)
|
||||||
|
|
||||||
|
//nolint: errchkjson
|
||||||
_ = encoder.Encode(domain.NewError(
|
_ = encoder.Encode(domain.NewError(
|
||||||
domain.ErrorCodeInsufficientScope,
|
domain.ErrorCodeInsufficientScope,
|
||||||
"token with 'profile' scope is required to view profile data",
|
"token with 'profile' scope is required to view profile data",
|
||||||
|
@ -81,7 +83,7 @@ func (h *RequestHandler) handleUserInformation(ctx *http.RequestCtx) {
|
||||||
|
|
||||||
resp := new(UserInformationResponse)
|
resp := new(UserInformationResponse)
|
||||||
if userInfo == nil {
|
if userInfo == nil {
|
||||||
_ = encoder.Encode(resp)
|
_ = encoder.Encode(resp) //nolint: errchkjson
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -102,5 +104,5 @@ func (h *RequestHandler) handleUserInformation(ctx *http.RequestCtx) {
|
||||||
resp.Email = userInfo.GetEmail().String()
|
resp.Email = userInfo.GetEmail().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = encoder.Encode(resp)
|
_ = encoder.Encode(resp) //nolint: errchkjson
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,11 +78,13 @@ func NewDependencies(tb testing.TB) Dependencies {
|
||||||
config := domain.TestConfig(tb)
|
config := domain.TestConfig(tb)
|
||||||
|
|
||||||
return Dependencies{
|
return Dependencies{
|
||||||
profile: domain.TestProfile(tb),
|
config: config,
|
||||||
token: domain.TestToken(tb),
|
profile: domain.TestProfile(tb),
|
||||||
config: config,
|
profiles: profilerepo.NewMemoryProfileRepository(store),
|
||||||
store: store,
|
sessions: sessionrepo.NewMemorySessionRepository(store, config),
|
||||||
tokens: tokenrepo.NewMemoryTokenRepository(store),
|
store: store,
|
||||||
|
token: domain.TestToken(tb),
|
||||||
|
tokens: tokenrepo.NewMemoryTokenRepository(store),
|
||||||
tokenService: tokenucase.NewTokenUseCase(tokenucase.Config{
|
tokenService: tokenucase.NewTokenUseCase(tokenucase.Config{
|
||||||
Config: config,
|
Config: config,
|
||||||
Profiles: profilerepo.NewMemoryProfileRepository(store),
|
Profiles: profilerepo.NewMemoryProfileRepository(store),
|
||||||
|
|
24
main.go
24
main.go
|
@ -42,6 +42,7 @@ import (
|
||||||
metadatahttpdelivery "source.toby3d.me/toby3d/auth/internal/metadata/delivery/http"
|
metadatahttpdelivery "source.toby3d.me/toby3d/auth/internal/metadata/delivery/http"
|
||||||
"source.toby3d.me/toby3d/auth/internal/profile"
|
"source.toby3d.me/toby3d/auth/internal/profile"
|
||||||
profilehttprepo "source.toby3d.me/toby3d/auth/internal/profile/repository/http"
|
profilehttprepo "source.toby3d.me/toby3d/auth/internal/profile/repository/http"
|
||||||
|
profileucase "source.toby3d.me/toby3d/auth/internal/profile/usecase"
|
||||||
"source.toby3d.me/toby3d/auth/internal/session"
|
"source.toby3d.me/toby3d/auth/internal/session"
|
||||||
sessionmemoryrepo "source.toby3d.me/toby3d/auth/internal/session/repository/memory"
|
sessionmemoryrepo "source.toby3d.me/toby3d/auth/internal/session/repository/memory"
|
||||||
sessionsqlite3repo "source.toby3d.me/toby3d/auth/internal/session/repository/sqlite3"
|
sessionsqlite3repo "source.toby3d.me/toby3d/auth/internal/session/repository/sqlite3"
|
||||||
|
@ -66,6 +67,7 @@ type (
|
||||||
matcher language.Matcher
|
matcher language.Matcher
|
||||||
sessions session.UseCase
|
sessions session.UseCase
|
||||||
tickets ticket.UseCase
|
tickets ticket.UseCase
|
||||||
|
profiles profile.UseCase
|
||||||
tokens token.UseCase
|
tokens token.UseCase
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +195,7 @@ func main() {
|
||||||
opts.Clients = clienthttprepo.NewHTTPClientRepository(opts.Client)
|
opts.Clients = clienthttprepo.NewHTTPClientRepository(opts.Client)
|
||||||
opts.Profiles = profilehttprepo.NewHTPPClientRepository(opts.Client)
|
opts.Profiles = profilehttprepo.NewHTPPClientRepository(opts.Client)
|
||||||
|
|
||||||
r := router.New() //nolint: varnamelen
|
r := router.New()
|
||||||
NewApp(opts).Register(r)
|
NewApp(opts).Register(r)
|
||||||
//nolint: exhaustivestruct// too many options
|
//nolint: exhaustivestruct// too many options
|
||||||
r.ServeFilesCustom(path.Join(config.Server.StaticURLPrefix, "{filepath:*}"), &http.FS{
|
r.ServeFilesCustom(path.Join(config.Server.StaticURLPrefix, "{filepath:*}"), &http.FS{
|
||||||
|
@ -275,6 +277,7 @@ func NewApp(opts NewAppOptions) *App {
|
||||||
auth: authucase.NewAuthUseCase(opts.Sessions, opts.Profiles, config),
|
auth: authucase.NewAuthUseCase(opts.Sessions, opts.Profiles, config),
|
||||||
clients: clientucase.NewClientUseCase(opts.Clients),
|
clients: clientucase.NewClientUseCase(opts.Clients),
|
||||||
matcher: language.NewMatcher(message.DefaultCatalog.Languages()),
|
matcher: language.NewMatcher(message.DefaultCatalog.Languages()),
|
||||||
|
profiles: profileucase.NewProfileUseCase(opts.Profiles),
|
||||||
sessions: sessionucase.NewSessionUseCase(opts.Sessions),
|
sessions: sessionucase.NewSessionUseCase(opts.Sessions),
|
||||||
tickets: ticketucase.NewTicketUseCase(opts.Tickets, opts.Client, config),
|
tickets: ticketucase.NewTicketUseCase(opts.Tickets, opts.Client, config),
|
||||||
tokens: tokenucase.NewTokenUseCase(tokenucase.Config{
|
tokens: tokenucase.NewTokenUseCase(tokenucase.Config{
|
||||||
|
@ -316,14 +319,8 @@ func (app *App) Register(r *router.Router) {
|
||||||
domain.ScopeRead,
|
domain.ScopeRead,
|
||||||
domain.ScopeUpdate,
|
domain.ScopeUpdate,
|
||||||
},
|
},
|
||||||
ResponseTypesSupported: []domain.ResponseType{
|
ResponseTypesSupported: []domain.ResponseType{domain.ResponseTypeCode, domain.ResponseTypeID},
|
||||||
domain.ResponseTypeCode,
|
GrantTypesSupported: []domain.GrantType{domain.GrantTypeAuthorizationCode, domain.GrantTypeTicket},
|
||||||
domain.ResponseTypeID,
|
|
||||||
},
|
|
||||||
GrantTypesSupported: []domain.GrantType{
|
|
||||||
domain.GrantTypeAuthorizationCode,
|
|
||||||
domain.GrantTypeTicket,
|
|
||||||
},
|
|
||||||
CodeChallengeMethodsSupported: []domain.CodeChallengeMethod{
|
CodeChallengeMethodsSupported: []domain.CodeChallengeMethod{
|
||||||
domain.CodeChallengeMethodMD5,
|
domain.CodeChallengeMethodMD5,
|
||||||
domain.CodeChallengeMethodPLAIN,
|
domain.CodeChallengeMethodPLAIN,
|
||||||
|
@ -341,10 +338,11 @@ func (app *App) Register(r *router.Router) {
|
||||||
Tokens: app.tokens,
|
Tokens: app.tokens,
|
||||||
}).Register(r)
|
}).Register(r)
|
||||||
authhttpdelivery.NewRequestHandler(authhttpdelivery.NewRequestHandlerOptions{
|
authhttpdelivery.NewRequestHandler(authhttpdelivery.NewRequestHandlerOptions{
|
||||||
Auth: app.auth,
|
Auth: app.auth,
|
||||||
Clients: app.clients,
|
Clients: app.clients,
|
||||||
Config: config,
|
Config: config,
|
||||||
Matcher: app.matcher,
|
Matcher: app.matcher,
|
||||||
|
Profiles: app.profiles,
|
||||||
}).Register(r)
|
}).Register(r)
|
||||||
userhttpdelivery.NewRequestHandler(app.tokens, config).Register(r)
|
userhttpdelivery.NewRequestHandler(app.tokens, config).Register(r)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue