Created
August 3, 2018 13:39
-
-
Save koblas/770212499e0ca148f44a1d54d3e7031b to your computer and use it in GitHub Desktop.
graphql authentication wrapper
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package nresolver | |
import ( | |
"errors" | |
"github.com/graphql-go/graphql" | |
"github.com/koblas/projectx/server-go/pkg/contextkey" | |
"github.com/koblas/projectx/server-go/pkg/service" | |
) | |
func wrapIsAuth(wrap func(graphql.ResolveParams) (interface{}, error)) func(graphql.ResolveParams) (interface{}, error) { | |
return func(p graphql.ResolveParams) (interface{}, error) { | |
ctx := p.Context | |
logger := service.LoggerFromContext(ctx) | |
if auth, ok := ctx.Value(contextkey.IsAuthorized).(bool); !ok || !auth { | |
logger.Infof("Missing Authentication") | |
return nil, errors.New("Need Authentication") | |
} | |
return wrap(p) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment