improved authentication check

This commit is contained in:
2021-09-24 15:49:51 +02:00
parent ed932e3c92
commit f59f3183f2
4 changed files with 27 additions and 32 deletions

View File

@@ -6,6 +6,7 @@ import (
"github.com/graph-gophers/dataloader"
"github.com/graphql-go/graphql"
s3errors "git.kapelle.org/niklas/s3browser/internal/errors"
helper "git.kapelle.org/niklas/s3browser/internal/helper"
types "git.kapelle.org/niklas/s3browser/internal/types"
log "github.com/sirupsen/logrus"
@@ -23,8 +24,8 @@ func GraphqlSchema() (graphql.Schema, error) {
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if is, err := helper.IsAuth(p.Context); !is {
return nil, err
if helper.IsAuthenticated(p.Context) {
return nil, s3errors.ErrNotAuthenticated
}
path, ok := p.Args["path"].(string)
@@ -48,8 +49,8 @@ func GraphqlSchema() (graphql.Schema, error) {
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if is, err := helper.IsAuth(p.Context); !is {
return nil, err
if helper.IsAuthenticated(p.Context) {
return nil, s3errors.ErrNotAuthenticated
}
path, ok := p.Args["path"].(string)
@@ -73,8 +74,8 @@ func GraphqlSchema() (graphql.Schema, error) {
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if is, err := helper.IsAuth(p.Context); !is {
return nil, err
if helper.IsAuthenticated(p.Context) {
return nil, s3errors.ErrNotAuthenticated
}
id, ok := p.Args["id"].(string)
@@ -94,7 +95,7 @@ func GraphqlSchema() (graphql.Schema, error) {
Type: graphql.NewNonNull(graphql.Boolean),
Description: "True if the user is authorized",
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
auth, _ := helper.IsAuth(p.Context)
auth := helper.IsAuthenticated(p.Context)
return auth, nil
},
@@ -110,8 +111,8 @@ func GraphqlSchema() (graphql.Schema, error) {
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if is, err := helper.IsAuth(p.Context); !is {
return nil, err
if helper.IsAuthenticated(p.Context) {
return nil, s3errors.ErrNotAuthenticated
}
id, ok := p.Args["id"].(string)
@@ -135,8 +136,8 @@ func GraphqlSchema() (graphql.Schema, error) {
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if is, err := helper.IsAuth(p.Context); !is {
return nil, err
if helper.IsAuthenticated(p.Context) {
return nil, s3errors.ErrNotAuthenticated
}
src, ok := p.Args["src"].(string)
@@ -164,8 +165,8 @@ func GraphqlSchema() (graphql.Schema, error) {
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if is, err := helper.IsAuth(p.Context); !is {
return nil, err
if helper.IsAuthenticated(p.Context) {
return nil, s3errors.ErrNotAuthenticated
}
src, ok := p.Args["src"].(string)
@@ -190,8 +191,8 @@ func GraphqlSchema() (graphql.Schema, error) {
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if is, err := helper.IsAuth(p.Context); !is {
return nil, err
if helper.IsAuthenticated(p.Context) {
return nil, s3errors.ErrNotAuthenticated
}
path, ok := p.Args["path"].(string)
@@ -212,8 +213,8 @@ func GraphqlSchema() (graphql.Schema, error) {
},
},
Resolve: func(p graphql.ResolveParams) (interface{}, error) {
if is, err := helper.IsAuth(p.Context); !is {
return nil, err
if helper.IsAuthenticated(p.Context) {
return nil, s3errors.ErrNotAuthenticated
}
path, ok := p.Args["path"].(string)