🎨 Format GolangCI-Lint comments
This commit is contained in:
parent
c6699bb312
commit
e0d9212678
|
@ -347,7 +347,7 @@ func NewAuthAuthorizationRequest() *AuthAuthorizationRequest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint: cyclop
|
//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().QueryString(), r); err != nil {
|
if err := form.Unmarshal(ctx.QueryArgs().QueryString(), r); err != nil {
|
||||||
|
@ -384,7 +384,7 @@ func NewAuthVerifyRequest() *AuthVerifyRequest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint: funlen,cyclop
|
//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)
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ func TestAuthorize(t *testing.T) {
|
||||||
deps.store.Store(path.Join(userrepo.DefaultPathPrefix, me.String()), user)
|
deps.store.Store(path.Join(userrepo.DefaultPathPrefix, me.String()), user)
|
||||||
|
|
||||||
r := router.New()
|
r := router.New()
|
||||||
//nolint: exhaustivestruct
|
//nolint:exhaustivestruct
|
||||||
delivery.NewRequestHandler(delivery.NewRequestHandlerOptions{
|
delivery.NewRequestHandler(delivery.NewRequestHandlerOptions{
|
||||||
Auth: deps.authService,
|
Auth: deps.authService,
|
||||||
Clients: deps.clientService,
|
Clients: deps.clientService,
|
||||||
|
|
|
@ -87,7 +87,7 @@ func (h *RequestHandler) handleRender(ctx *http.RequestCtx) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint: funlen
|
//nolint:unlen
|
||||||
func (h *RequestHandler) handleCallback(ctx *http.RequestCtx) {
|
func (h *RequestHandler) handleCallback(ctx *http.RequestCtx) {
|
||||||
ctx.SetContentType(common.MIMETextHTMLCharsetUTF8)
|
ctx.SetContentType(common.MIMETextHTMLCharsetUTF8)
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ func (repo *httpClientRepository) Get(ctx context.Context, cid *domain.ClientID)
|
||||||
return client, nil
|
return client, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint: gocognit, cyclop
|
//nolint:gocognit,cyclop
|
||||||
func extract(dst *domain.Client, src *http.Response) {
|
func extract(dst *domain.Client, src *http.Response) {
|
||||||
for _, endpoint := range httputil.ExtractEndpoints(src, relRedirectURI) {
|
for _, endpoint := range httputil.ExtractEndpoints(src, relRedirectURI) {
|
||||||
if !containsURL(dst.RedirectURI, endpoint) {
|
if !containsURL(dst.RedirectURI, endpoint) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ type Action struct {
|
||||||
uid string
|
uid string
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint: gochecknoglobals // structs cannot be constants
|
//nolint:gochecknoglobals // structs cannot be constants
|
||||||
var (
|
var (
|
||||||
ActionUnd = Action{uid: ""} // "und"
|
ActionUnd = Action{uid: ""} // "und"
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ var (
|
||||||
|
|
||||||
var ErrActionSyntax error = NewError(ErrorCodeInvalidRequest, "unknown action method", "")
|
var ErrActionSyntax error = NewError(ErrorCodeInvalidRequest, "unknown action method", "")
|
||||||
|
|
||||||
//nolint: gochecknoglobals
|
//nolint:gochecknoglobals
|
||||||
var uidsActions = map[string]Action{
|
var uidsActions = map[string]Action{
|
||||||
ActionRevoke.uid: ActionRevoke,
|
ActionRevoke.uid: ActionRevoke,
|
||||||
ActionTicket.uid: ActionTicket,
|
ActionTicket.uid: ActionTicket,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//nolint: dupl
|
//nolint:dupl
|
||||||
package domain_test
|
package domain_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -16,14 +16,15 @@ type ClientID struct {
|
||||||
clientID *http.URI
|
clientID *http.URI
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint: gochecknoglobals // slices cannot be constants
|
//nolint:gochecknoglobals // slices cannot be constants
|
||||||
var (
|
var (
|
||||||
localhostIPv4 = netaddr.MustParseIP("127.0.0.1")
|
localhostIPv4 = netaddr.MustParseIP("127.0.0.1")
|
||||||
localhostIPv6 = netaddr.MustParseIP("::1")
|
localhostIPv6 = netaddr.MustParseIP("::1")
|
||||||
)
|
)
|
||||||
|
|
||||||
// ParseClientID parse string as client ID URL identifier.
|
// ParseClientID parse string as client ID URL identifier.
|
||||||
//nolint: funlen, cyclop
|
//
|
||||||
|
//nolint:funlen,cyclop
|
||||||
func ParseClientID(src string) (*ClientID, error) {
|
func ParseClientID(src string) (*ClientID, error) {
|
||||||
cid := http.AcquireURI()
|
cid := http.AcquireURI()
|
||||||
if err := cid.Parse(nil, []byte(src)); err != nil {
|
if err := cid.Parse(nil, []byte(src)); err != nil {
|
||||||
|
@ -82,7 +83,7 @@ func ParseClientID(src string) (*ClientID, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ipPort, err := netaddr.ParseIPPort(domain)
|
ipPort, err := netaddr.ParseIPPort(domain)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
//nolint: nilerr // ClientID does not contain an IP address, so it is valid
|
//nolint:nilerr // ClientID does not contain an IP address, so it is valid
|
||||||
return &ClientID{clientID: cid}, nil
|
return &ClientID{clientID: cid}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package domain
|
package domain
|
||||||
|
|
||||||
//nolint: gosec // support old clients
|
//nolint:gosec // support old clients
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
|
@ -23,7 +23,7 @@ type CodeChallengeMethod struct {
|
||||||
uid string
|
uid string
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint: gochecknoglobals // structs cannot be constants
|
//nolint:gochecknoglobals // structs cannot be constants
|
||||||
var (
|
var (
|
||||||
CodeChallengeMethodUnd = CodeChallengeMethod{uid: ""} // "und"
|
CodeChallengeMethodUnd = CodeChallengeMethod{uid: ""} // "und"
|
||||||
CodeChallengeMethodPLAIN = CodeChallengeMethod{uid: "plain"} // "PLAIN"
|
CodeChallengeMethodPLAIN = CodeChallengeMethod{uid: "plain"} // "PLAIN"
|
||||||
|
@ -39,7 +39,7 @@ var ErrCodeChallengeMethodUnknown error = NewError(
|
||||||
"https://indieauth.net/source/#authorization-request",
|
"https://indieauth.net/source/#authorization-request",
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint: gochecknoglobals // maps cannot be constants
|
//nolint:gochecknoglobals // maps cannot be constants
|
||||||
var uidsMethods = map[string]CodeChallengeMethod{
|
var uidsMethods = map[string]CodeChallengeMethod{
|
||||||
CodeChallengeMethodMD5.uid: CodeChallengeMethodMD5,
|
CodeChallengeMethodMD5.uid: CodeChallengeMethodMD5,
|
||||||
CodeChallengeMethodPLAIN.uid: CodeChallengeMethodPLAIN,
|
CodeChallengeMethodPLAIN.uid: CodeChallengeMethodPLAIN,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
package domain_test
|
package domain_test
|
||||||
|
|
||||||
//nolint: gosec // support old clients
|
//nolint:gosec // support old clients
|
||||||
import (
|
import (
|
||||||
"crypto/md5"
|
"crypto/md5"
|
||||||
"crypto/sha1"
|
"crypto/sha1"
|
||||||
|
@ -110,7 +110,7 @@ func TestCodeChallengeMethod_String(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint: gosec // support old clients
|
//nolint:gosec // support old clients
|
||||||
func TestCodeChallengeMethod_Validate(t *testing.T) {
|
func TestCodeChallengeMethod_Validate(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|
|
@ -78,7 +78,8 @@ type (
|
||||||
)
|
)
|
||||||
|
|
||||||
// TestConfig returns a valid config for tests.
|
// TestConfig returns a valid config for tests.
|
||||||
//nolint: gomnd // testing domain can contains non-standart values
|
//
|
||||||
|
//nolint:gomnd // testing domain can contains non-standart values
|
||||||
func TestConfig(tb testing.TB) *Config {
|
func TestConfig(tb testing.TB) *Config {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ func TestParseEmail(t *testing.T) {
|
||||||
func TestEmail_String(t *testing.T) {
|
func TestEmail_String(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
email := domain.TestEmail(t) //nolint: ifshort
|
email := domain.TestEmail(t) //nolint:ifshort
|
||||||
if result := email.String(); result != fmt.Sprint(email) {
|
if result := email.String(); result != fmt.Sprint(email) {
|
||||||
t.Errorf("String() = %v, want %v", result, email)
|
t.Errorf("String() = %v, want %v", result, email)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
|
|
||||||
type (
|
type (
|
||||||
// Error describes the format of a typical IndieAuth error.
|
// Error describes the format of a typical IndieAuth error.
|
||||||
//nolint: tagliatelle // RFC 6749 section 5.2
|
//nolint:tagliatelle // RFC 6749 section 5.2
|
||||||
Error struct {
|
Error struct {
|
||||||
// A single error code.
|
// A single error code.
|
||||||
Code ErrorCode `json:"error"`
|
Code ErrorCode `json:"error"`
|
||||||
|
@ -150,7 +150,7 @@ var (
|
||||||
|
|
||||||
var ErrErrorCodeUnknown error = NewError(ErrorCodeInvalidRequest, "unknown error code", "")
|
var ErrErrorCodeUnknown error = NewError(ErrorCodeInvalidRequest, "unknown error code", "")
|
||||||
|
|
||||||
//nolint: gochecknoglobals // maps cannot be constants
|
//nolint:gochecknoglobals // maps cannot be constants
|
||||||
var uidsErrorCodes = map[string]ErrorCode{
|
var uidsErrorCodes = map[string]ErrorCode{
|
||||||
ErrorCodeAccessDenied.uid: ErrorCodeAccessDenied,
|
ErrorCodeAccessDenied.uid: ErrorCodeAccessDenied,
|
||||||
ErrorCodeInsufficientScope.uid: ErrorCodeInsufficientScope,
|
ErrorCodeInsufficientScope.uid: ErrorCodeInsufficientScope,
|
||||||
|
|
|
@ -16,7 +16,7 @@ type GrantType struct {
|
||||||
uid string
|
uid string
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint: gochecknoglobals // structs cannot be constants
|
//nolint:gochecknoglobals // structs cannot be constants
|
||||||
var (
|
var (
|
||||||
GrantTypeUnd = GrantType{uid: ""} // "und"
|
GrantTypeUnd = GrantType{uid: ""} // "und"
|
||||||
GrantTypeAuthorizationCode = GrantType{uid: "authorization_code"} // "authorization_code"
|
GrantTypeAuthorizationCode = GrantType{uid: "authorization_code"} // "authorization_code"
|
||||||
|
@ -32,7 +32,7 @@ var ErrGrantTypeUnknown error = NewError(
|
||||||
"",
|
"",
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint: gochecknoglobals // maps cannot be constants
|
//nolint:gochecknoglobals // maps cannot be constants
|
||||||
var uidsGrantTypes = map[string]GrantType{
|
var uidsGrantTypes = map[string]GrantType{
|
||||||
GrantTypeAuthorizationCode.uid: GrantTypeAuthorizationCode,
|
GrantTypeAuthorizationCode.uid: GrantTypeAuthorizationCode,
|
||||||
GrantTypeRefreshToken.uid: GrantTypeRefreshToken,
|
GrantTypeRefreshToken.uid: GrantTypeRefreshToken,
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//nolint: dupl
|
//nolint:dupl
|
||||||
package domain_test
|
package domain_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -17,7 +17,8 @@ type Me struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ParseMe parse string as me URL identifier.
|
// ParseMe parse string as me URL identifier.
|
||||||
//nolint: funlen, cyclop
|
//
|
||||||
|
//nolint:funlen,cyclop
|
||||||
func ParseMe(raw string) (*Me, error) {
|
func ParseMe(raw string) (*Me, error) {
|
||||||
id := http.AcquireURI()
|
id := http.AcquireURI()
|
||||||
if err := id.Parse(nil, []byte(raw)); err != nil {
|
if err := id.Parse(nil, []byte(raw)); err != nil {
|
||||||
|
|
|
@ -21,7 +21,7 @@ type Provider struct {
|
||||||
URL string
|
URL string
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint: gochecknoglobals // structs cannot be contants
|
//nolint:gochecknoglobals // structs cannot be contants
|
||||||
var (
|
var (
|
||||||
ProviderDirect = Provider{
|
ProviderDirect = Provider{
|
||||||
AuthURL: "/authorize",
|
AuthURL: "/authorize",
|
||||||
|
|
|
@ -14,7 +14,7 @@ type ResponseType struct {
|
||||||
uid string
|
uid string
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint: gochecknoglobals // structs cannot be constants
|
//nolint:gochecknoglobals // structs cannot be constants
|
||||||
var (
|
var (
|
||||||
ResponseTypeUnd = ResponseType{uid: ""} // "und"
|
ResponseTypeUnd = ResponseType{uid: ""} // "und"
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
//nolint: dupl
|
//nolint:dupl
|
||||||
package domain_test
|
package domain_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
@ -23,7 +23,7 @@ type (
|
||||||
|
|
||||||
var ErrScopeUnknown error = NewError(ErrorCodeInvalidRequest, "unknown scope", "https://indieweb.org/scope")
|
var ErrScopeUnknown error = NewError(ErrorCodeInvalidRequest, "unknown scope", "https://indieweb.org/scope")
|
||||||
|
|
||||||
//nolint: gochecknoglobals // structs cannot be constants
|
//nolint:gochecknoglobals // structs cannot be constants
|
||||||
var (
|
var (
|
||||||
ScopeUnd = Scope{uid: ""} // "und"
|
ScopeUnd = Scope{uid: ""} // "und"
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ var (
|
||||||
ScopeEmail = Scope{uid: "email"} // "email"
|
ScopeEmail = Scope{uid: "email"} // "email"
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint: gochecknoglobals // maps cannot be constants
|
//nolint:gochecknoglobals // maps cannot be constants
|
||||||
var uidsScopes = map[string]Scope{
|
var uidsScopes = map[string]Scope{
|
||||||
ScopeBlock.uid: ScopeBlock,
|
ScopeBlock.uid: ScopeBlock,
|
||||||
ScopeChannels.uid: ScopeChannels,
|
ScopeChannels.uid: ScopeChannels,
|
||||||
|
|
|
@ -95,7 +95,6 @@ func TestScopes_MarshalJSON(t *testing.T) {
|
||||||
func TestScope_String(t *testing.T) {
|
func TestScope_String(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
//nolint: paralleltest // false positive, in is used
|
|
||||||
for _, tc := range []struct {
|
for _, tc := range []struct {
|
||||||
in domain.Scope
|
in domain.Scope
|
||||||
out string
|
out string
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"source.toby3d.me/toby3d/auth/internal/random"
|
"source.toby3d.me/toby3d/auth/internal/random"
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint: tagliatelle
|
//nolint:tagliatelle
|
||||||
type Session struct {
|
type Session struct {
|
||||||
ClientID *ClientID `json:"client_id"`
|
ClientID *ClientID `json:"client_id"`
|
||||||
RedirectURI *URL `json:"redirect_uri"`
|
RedirectURI *URL `json:"redirect_uri"`
|
||||||
|
@ -19,7 +19,8 @@ type Session struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestSession returns valid random generated session for tests.
|
// TestSession returns valid random generated session for tests.
|
||||||
//nolint: gomnd // testing domain can contains non-standart values
|
//
|
||||||
|
//nolint:gomnd // testing domain can contains non-standart values
|
||||||
func TestSession(tb testing.TB) *Session {
|
func TestSession(tb testing.TB) *Session {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,8 @@ type (
|
||||||
)
|
)
|
||||||
|
|
||||||
// DefaultNewTokenOptions describes the default settings for NewToken.
|
// DefaultNewTokenOptions describes the default settings for NewToken.
|
||||||
//nolint: gochecknoglobals, gomnd
|
//
|
||||||
|
//nolint:gochecknoglobals,gomnd
|
||||||
var DefaultNewTokenOptions = NewTokenOptions{
|
var DefaultNewTokenOptions = NewTokenOptions{
|
||||||
Expiration: 0,
|
Expiration: 0,
|
||||||
Scope: nil,
|
Scope: nil,
|
||||||
|
@ -49,7 +50,8 @@ var DefaultNewTokenOptions = NewTokenOptions{
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewToken create a new token by provided options.
|
// NewToken create a new token by provided options.
|
||||||
//nolint: 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
|
||||||
|
@ -109,7 +111,8 @@ func NewToken(opts NewTokenOptions) (*Token, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestToken returns valid random generated token for tests.
|
// TestToken returns valid random generated token for tests.
|
||||||
//nolint: gomnd // testing domain can contains non-standart values
|
//
|
||||||
|
//nolint:gomnd // testing domain can contains non-standart values
|
||||||
func TestToken(tb testing.TB) *Token {
|
func TestToken(tb testing.TB) *Token {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
|
|
||||||
|
|
|
@ -95,7 +95,7 @@ func ExtractMetadata(resp *http.Response, client *http.Client) (*domain.Metadata
|
||||||
}
|
}
|
||||||
|
|
||||||
func ExtractProperty(resp *http.Response, itemType, key string) []interface{} {
|
func ExtractProperty(resp *http.Response, itemType, key string) []interface{} {
|
||||||
//nolint: exhaustivestruct // only Host part in url.URL is needed
|
//nolint:exhaustivestruct // only Host part in url.URL is needed
|
||||||
data := microformats.Parse(bytes.NewReader(resp.Body()), &url.URL{
|
data := microformats.Parse(bytes.NewReader(resp.Body()), &url.URL{
|
||||||
Host: string(resp.Header.Peek(http.HeaderHost)),
|
Host: string(resp.Header.Peek(http.HeaderHost)),
|
||||||
})
|
})
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
//nolint: tagliatelle // https://indieauth.net/source/#indieauth-server-metadata
|
//nolint:tagliatelle // https://indieauth.net/source/#indieauth-server-metadata
|
||||||
MetadataResponse struct {
|
MetadataResponse struct {
|
||||||
// The server's issuer identifier.
|
// The server's issuer identifier.
|
||||||
Issuer string `json:"issuer"`
|
Issuer string `json:"issuer"`
|
||||||
|
@ -27,13 +27,13 @@ type (
|
||||||
|
|
||||||
// JSON array containing a list of client authentication methods
|
// JSON array containing a list of client authentication methods
|
||||||
// supported by this introspection endpoint.
|
// supported by this introspection endpoint.
|
||||||
IntrospectionEndpointAuthMethodsSupported []string `json:"introspection_endpoint_auth_methods_supported,omitempty"` //nolint: lll
|
IntrospectionEndpointAuthMethodsSupported []string `json:"introspection_endpoint_auth_methods_supported,omitempty"` //nolint:lll
|
||||||
|
|
||||||
// The Revocation Endpoint.
|
// The Revocation Endpoint.
|
||||||
RevocationEndpoint string `json:"revocation_endpoint,omitempty"`
|
RevocationEndpoint string `json:"revocation_endpoint,omitempty"`
|
||||||
|
|
||||||
// JSON array containing the value "none".
|
// JSON array containing the value "none".
|
||||||
RevocationEndpointAuthMethodsSupported []string `json:"revocation_endpoint_auth_methods_supported,omitempty"` //nolint: lll
|
RevocationEndpointAuthMethodsSupported []string `json:"revocation_endpoint_auth_methods_supported,omitempty"` //nolint:lll
|
||||||
|
|
||||||
// JSON array containing scope values supported by the
|
// JSON array containing scope values supported by the
|
||||||
// IndieAuth server.
|
// IndieAuth server.
|
||||||
|
@ -54,7 +54,7 @@ type (
|
||||||
|
|
||||||
// Boolean parameter indicating whether the authorization server
|
// Boolean parameter indicating whether the authorization server
|
||||||
// provides the iss parameter.
|
// provides the iss parameter.
|
||||||
AuthorizationResponseIssParameterSupported bool `json:"authorization_response_iss_parameter_supported,omitempty"` //nolint: lll
|
AuthorizationResponseIssParameterSupported bool `json:"authorization_response_iss_parameter_supported,omitempty"` //nolint:lll
|
||||||
|
|
||||||
// The User Info Endpoint.
|
// The User Info Endpoint.
|
||||||
UserinfoEndpoint string `json:"userinfo_endpoint,omitempty"`
|
UserinfoEndpoint string `json:"userinfo_endpoint,omitempty"`
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
//nolint: tagliatelle,lll
|
//nolint:tagliatelle,lll
|
||||||
Metadata struct {
|
Metadata struct {
|
||||||
Issuer *domain.ClientID `json:"issuer"`
|
Issuer *domain.ClientID `json:"issuer"`
|
||||||
AuthorizationEndpoint *domain.URL `json:"authorization_endpoint"`
|
AuthorizationEndpoint *domain.URL `json:"authorization_endpoint"`
|
||||||
|
@ -72,7 +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)
|
//nolint:exhaustivestruct // TODO(toby3d)
|
||||||
return &domain.Metadata{
|
return &domain.Metadata{
|
||||||
AuthorizationEndpoint: data.AuthorizationEndpoint,
|
AuthorizationEndpoint: data.AuthorizationEndpoint,
|
||||||
AuthorizationResponseIssParameterSupported: data.AuthorizationResponseIssParameterSupported,
|
AuthorizationResponseIssParameterSupported: data.AuthorizationResponseIssParameterSupported,
|
||||||
|
|
|
@ -32,7 +32,7 @@ func NewHTPPClientRepository(client *http.Client) profile.Repository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint: cyclop
|
//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)
|
||||||
|
|
|
@ -67,7 +67,7 @@ func (repo *sqlite3SessionRepository) Create(ctx context.Context, session *domai
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *sqlite3SessionRepository) Get(ctx context.Context, code string) (*domain.Session, error) {
|
func (repo *sqlite3SessionRepository) Get(ctx context.Context, code string) (*domain.Session, error) {
|
||||||
s := new(Session) //nolint: varnamelen // cannot redaclare import
|
s := new(Session) //nolint:varnamelen // cannot redaclare import
|
||||||
if err := repo.db.GetContext(ctx, s, QueryGet, code); err != nil {
|
if err := repo.db.GetContext(ctx, s, QueryGet, code); err != nil {
|
||||||
return nil, fmt.Errorf("cannot find session in db: %w", err)
|
return nil, fmt.Errorf("cannot find session in db: %w", err)
|
||||||
}
|
}
|
||||||
|
@ -83,7 +83,7 @@ func (repo *sqlite3SessionRepository) Get(ctx context.Context, code string) (*do
|
||||||
}
|
}
|
||||||
|
|
||||||
func (repo *sqlite3SessionRepository) GetAndDelete(ctx context.Context, code string) (*domain.Session, error) {
|
func (repo *sqlite3SessionRepository) GetAndDelete(ctx context.Context, code string) (*domain.Session, error) {
|
||||||
s := new(Session) //nolint: varnamelen // cannot redaclare import
|
s := new(Session) //nolint:varnamelen // cannot redaclare import
|
||||||
|
|
||||||
tx, err := repo.db.Beginx()
|
tx, err := repo.db.Beginx()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -93,7 +93,7 @@ func (repo *sqlite3SessionRepository) GetAndDelete(ctx context.Context, code str
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = tx.GetContext(ctx, s, QueryGet, code); err != nil {
|
if err = tx.GetContext(ctx, s, QueryGet, code); err != nil {
|
||||||
//nolint: errcheck // deffered method
|
//nolint:errcheck // deffered method
|
||||||
defer tx.Rollback()
|
defer tx.Rollback()
|
||||||
|
|
||||||
if errors.Is(err, sql.ErrNoRows) {
|
if errors.Is(err, sql.ErrNoRows) {
|
||||||
|
|
|
@ -24,7 +24,7 @@ var (
|
||||||
func New(tb testing.TB, handler http.RequestHandler) (*http.Client, *http.Server, func()) {
|
func New(tb testing.TB, handler http.RequestHandler) (*http.Client, *http.Server, func()) {
|
||||||
tb.Helper()
|
tb.Helper()
|
||||||
|
|
||||||
//nolint: exhaustivestruct
|
//nolint:exhaustivestruct
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
CloseOnShutdown: true,
|
CloseOnShutdown: true,
|
||||||
DisableKeepalive: true,
|
DisableKeepalive: true,
|
||||||
|
@ -34,16 +34,16 @@ func New(tb testing.TB, handler http.RequestHandler) (*http.Client, *http.Server
|
||||||
|
|
||||||
ln := httputil.NewInmemoryListener()
|
ln := httputil.NewInmemoryListener()
|
||||||
|
|
||||||
//nolint: errcheck
|
//nolint:errcheck
|
||||||
go server.ServeTLSEmbed(ln, certData, keyData)
|
go server.ServeTLSEmbed(ln, certData, keyData)
|
||||||
|
|
||||||
//nolint: exhaustivestruct
|
//nolint:exhaustivestruct
|
||||||
client := &http.Client{
|
client := &http.Client{
|
||||||
TLSConfig: &tls.Config{
|
TLSConfig: &tls.Config{
|
||||||
InsecureSkipVerify: true, //nolint: gosec
|
InsecureSkipVerify: true, //nolint:gosec
|
||||||
},
|
},
|
||||||
Dial: func(addr string) (net.Conn, error) {
|
Dial: func(addr string) (net.Conn, error) {
|
||||||
return ln.Dial() //nolint: wrapcheck
|
return ln.Dial() //nolint:wrapcheck
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +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
|
//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 {
|
||||||
|
|
|
@ -73,7 +73,7 @@ func (repo *sqlite3TicketRepository) GetAndDelete(ctx context.Context, rawTicket
|
||||||
|
|
||||||
tkt := new(Ticket)
|
tkt := new(Ticket)
|
||||||
if err = tx.GetContext(ctx, tkt, QueryGet, rawTicket); err != nil {
|
if err = tx.GetContext(ctx, tkt, QueryGet, rawTicket); err != nil {
|
||||||
//nolint: errcheck // deffered method
|
//nolint:errcheck // deffered method
|
||||||
defer tx.Rollback()
|
defer tx.Rollback()
|
||||||
|
|
||||||
if errors.Is(err, sql.ErrNoRows) {
|
if errors.Is(err, sql.ErrNoRows) {
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
//nolint: tagliatelle // https://indieauth.net/source/#access-token-response
|
//nolint:tagliatelle // https://indieauth.net/source/#access-token-response
|
||||||
AccessToken struct {
|
AccessToken struct {
|
||||||
Me *domain.Me `json:"me"`
|
Me *domain.Me `json:"me"`
|
||||||
Profile *Profile `json:"profile,omitempty"`
|
Profile *Profile `json:"profile,omitempty"`
|
||||||
|
|
|
@ -55,7 +55,7 @@ type (
|
||||||
Token string `form:"token"`
|
Token string `form:"token"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint: tagliatelle // https://indieauth.net/source/#access-token-response
|
//nolint:tagliatelle // https://indieauth.net/source/#access-token-response
|
||||||
TokenExchangeResponse struct {
|
TokenExchangeResponse struct {
|
||||||
// The OAuth 2.0 Bearer Token RFC6750.
|
// The OAuth 2.0 Bearer Token RFC6750.
|
||||||
AccessToken string `json:"access_token"`
|
AccessToken string `json:"access_token"`
|
||||||
|
@ -90,7 +90,7 @@ type (
|
||||||
Email string `json:"email,omitempty"`
|
Email string `json:"email,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint: tagliatelle // https://indieauth.net/source/#access-token-verification-response
|
//nolint:tagliatelle // https://indieauth.net/source/#access-token-verification-response
|
||||||
TokenIntrospectResponse struct {
|
TokenIntrospectResponse struct {
|
||||||
// Boolean indicator of whether or not the presented token is
|
// Boolean indicator of whether or not the presented token is
|
||||||
// currently active.
|
// currently active.
|
||||||
|
@ -138,7 +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
|
//nolint:exhaustivestruct
|
||||||
middleware.JWTWithConfig(middleware.JWTConfig{
|
middleware.JWTWithConfig(middleware.JWTConfig{
|
||||||
AuthScheme: "Bearer",
|
AuthScheme: "Bearer",
|
||||||
ContextKey: "token",
|
ContextKey: "token",
|
||||||
|
@ -227,7 +227,7 @@ func (h *RequestHandler) handleAction(ctx *http.RequestCtx) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint: funlen
|
//nolint:funlen
|
||||||
func (h *RequestHandler) handleExchange(ctx *http.RequestCtx) {
|
func (h *RequestHandler) handleExchange(ctx *http.RequestCtx) {
|
||||||
ctx.SetContentType(common.MIMEApplicationJSONCharsetUTF8)
|
ctx.SetContentType(common.MIMEApplicationJSONCharsetUTF8)
|
||||||
|
|
||||||
|
|
|
@ -117,7 +117,7 @@ func TestRevocation(t *testing.T) {
|
||||||
t.Errorf("POST %s = %d, want %d", requestURL, result, http.StatusOK)
|
t.Errorf("POST %s = %d, want %d", requestURL, result, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
expBody := []byte("{}") //nolint: ifshort
|
expBody := []byte("{}") //nolint:ifshort
|
||||||
if result := bytes.TrimSpace(resp.Body()); !bytes.Equal(result, expBody) {
|
if result := bytes.TrimSpace(resp.Body()); !bytes.Equal(result, expBody) {
|
||||||
t.Errorf("POST %s = %s, want %s", requestURL, result, expBody)
|
t.Errorf("POST %s = %s, want %s", requestURL, result, expBody)
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ import (
|
||||||
repository "source.toby3d.me/toby3d/auth/internal/token/repository/sqlite3"
|
repository "source.toby3d.me/toby3d/auth/internal/token/repository/sqlite3"
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint: gochecknoglobals // slices cannot be contants
|
//nolint:gochecknoglobals // slices cannot be contants
|
||||||
var tableColumns = []string{"created_at", "access_token", "client_id", "me", "scope"}
|
var tableColumns = []string{"created_at", "access_token", "client_id", "me", "scope"}
|
||||||
|
|
||||||
func TestCreate(t *testing.T) {
|
func TestCreate(t *testing.T) {
|
||||||
|
|
|
@ -41,7 +41,7 @@ func NewTokenUseCase(config Config) token.UseCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint: cyclop
|
//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,
|
||||||
) {
|
) {
|
||||||
|
@ -129,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 //nolint: nilerr // it's okay to return result without profile
|
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 {
|
||||||
|
|
|
@ -37,7 +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
|
//nolint:exhaustivestruct
|
||||||
middleware.JWTWithConfig(middleware.JWTConfig{
|
middleware.JWTWithConfig(middleware.JWTConfig{
|
||||||
AuthScheme: "Bearer",
|
AuthScheme: "Bearer",
|
||||||
ContextKey: "token",
|
ContextKey: "token",
|
||||||
|
@ -63,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) //nolint: errchkjson
|
_ = encoder.Encode(err) //nolint:errchkjson
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -71,7 +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
|
//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",
|
||||||
|
@ -83,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) //nolint: errchkjson
|
_ = encoder.Encode(resp) //nolint:errchkjson
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -104,5 +104,5 @@ func (h *RequestHandler) handleUserInformation(ctx *http.RequestCtx) {
|
||||||
resp.Email = userInfo.GetEmail().String()
|
resp.Email = userInfo.GetEmail().String()
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = encoder.Encode(resp) //nolint: errchkjson
|
_ = encoder.Encode(resp) //nolint:errchkjson
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ func (repo *httpUserRepository) Get(ctx context.Context, me *domain.Me) (*domain
|
||||||
return user, nil
|
return user, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint: cyclop
|
//nolint:cyclop
|
||||||
func extractUser(dst *domain.User, src *http.Response) {
|
func extractUser(dst *domain.User, src *http.Response) {
|
||||||
if dst.IndieAuthMetadata != nil {
|
if dst.IndieAuthMetadata != nil {
|
||||||
if endpoints := httputil.ExtractEndpoints(src, relIndieAuthMetadata); len(endpoints) > 0 {
|
if endpoints := httputil.ExtractEndpoints(src, relIndieAuthMetadata); len(endpoints) > 0 {
|
||||||
|
|
12
main.go
12
main.go
|
@ -87,7 +87,7 @@ const (
|
||||||
DefaultWriteTimeout time.Duration = 10 * time.Second
|
DefaultWriteTimeout time.Duration = 10 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint: gochecknoglobals
|
//nolint:gochecknoglobals
|
||||||
var (
|
var (
|
||||||
// NOTE(toby3d): write logs in stdout, see: https://12factor.net/logs
|
// NOTE(toby3d): write logs in stdout, see: https://12factor.net/logs
|
||||||
logger = log.New(os.Stdout, "IndieAuth\t", log.Lmsgprefix|log.LstdFlags|log.LUTC)
|
logger = log.New(os.Stdout, "IndieAuth\t", log.Lmsgprefix|log.LstdFlags|log.LUTC)
|
||||||
|
@ -100,7 +100,7 @@ var (
|
||||||
enablePprof bool
|
enablePprof bool
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint: gochecknoinits
|
//nolint:gochecknoinits
|
||||||
func init() {
|
func init() {
|
||||||
flag.StringVar(&configPath, "config", filepath.Join(".", "config.yml"), "load specific config")
|
flag.StringVar(&configPath, "config", filepath.Join(".", "config.yml"), "load specific config")
|
||||||
flag.BoolVar(&enablePprof, "pprof", false, "enable pprof mode")
|
flag.BoolVar(&enablePprof, "pprof", false, "enable pprof mode")
|
||||||
|
@ -157,7 +157,7 @@ func init() {
|
||||||
indieAuthClient.RedirectURI = []*domain.URL{redirectURI}
|
indieAuthClient.RedirectURI = []*domain.URL{redirectURI}
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint: funlen, cyclop // "god object" and the entry point of all modules
|
//nolint:funlen,cyclop // "god object" and the entry point of all modules
|
||||||
func main() {
|
func main() {
|
||||||
var opts NewAppOptions
|
var opts NewAppOptions
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ func main() {
|
||||||
|
|
||||||
go opts.Sessions.GC()
|
go opts.Sessions.GC()
|
||||||
|
|
||||||
//nolint: exhaustivestruct // too many options
|
//nolint:exhaustivestruct // too many options
|
||||||
opts.Client = &http.Client{
|
opts.Client = &http.Client{
|
||||||
Name: fmt.Sprintf("%s/0.1 (+%s)", config.Name, config.Server.GetAddress()),
|
Name: fmt.Sprintf("%s/0.1 (+%s)", config.Name, config.Server.GetAddress()),
|
||||||
ReadTimeout: DefaultReadTimeout,
|
ReadTimeout: DefaultReadTimeout,
|
||||||
|
@ -197,7 +197,7 @@ func main() {
|
||||||
|
|
||||||
r := router.New()
|
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{
|
||||||
Root: config.Server.StaticRootPath,
|
Root: config.Server.StaticRootPath,
|
||||||
CacheDuration: DefaultCacheDuration,
|
CacheDuration: DefaultCacheDuration,
|
||||||
|
@ -211,7 +211,7 @@ func main() {
|
||||||
r.GET("/debug/pprof/{filepath:*}", pprofhandler.PprofHandler)
|
r.GET("/debug/pprof/{filepath:*}", pprofhandler.PprofHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint: exhaustivestruct
|
//nolint:exhaustivestruct
|
||||||
server := &http.Server{
|
server := &http.Server{
|
||||||
Name: fmt.Sprintf("IndieAuth/0.1 (+%s)", config.Server.GetAddress()),
|
Name: fmt.Sprintf("IndieAuth/0.1 (+%s)", config.Server.GetAddress()),
|
||||||
Handler: r.Handler,
|
Handler: r.Handler,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user