graphql-go / graphql-go/graphql
Question: implement authorization using extensions.
- Dominant language
- Go
- Stars
- 10.1k
- Forks
- 845
- PR merge metrics
- No merged PRs in 30d
Description
Hi!, first of all I want to thank you guys for your work in this project!,
I've been poking w authentication and authorization the last few days, I'm pretty much done w the authentication part (I receive the token via http headers and I parse it from a custom middleware, identify the current user and pass the information along using Context).
On the other hand, i'm still trying to figure out the best way to implement authorization, is it possible to do it with a custom extension?
So, to clarify, given the following extension, is it possible to implement a basic authorization flow? (see method ExecutionDidStart)
```
package extensions
import (
"context"
"github.com/graphql-go/graphql"
"github.com/graphql-go/graphql/gqlerrors"
)
type Authorization struct{}
func (t *Authorization) Init(ctx context.Context, p *graphql.Params) context.Context {
return ctx
}
func (t *Authorization) Name() string {
return "Authorization"
}
func (t *Authorization) HasResult() bool {
return false
}
func (t *Authorization) GetResult(ctx context.Context) interface{} {
return nil
}
func (t *Authorization) ParseDidStart(ctx context.Context) (context.Context, graphql.ParseFinishFunc) {
return ctx, func(err error) {}
}
func (t *Authorization) ValidationDidStart(ctx context.Context) (context.Context, graphql.ValidationFinishFunc) {
return ctx, func(errs []gqlerrors.FormattedError) {}
}
func (t *Authorization) ExecutionDidStart(ctx context.Context) (context.Context, graphql.ExecutionFinishFunc) {
// pick current session and params from ctx, if user is not authorized return an error somehow
return ctx, func(*graphql.Result) {}
}
func (t *Authorization) ResolveFieldDidStart(ctx context.Context, i *graphql.ResolveInfo) (context.Context, graphql.ResolveFieldFinishFunc) {
return ctx, func(v interface{}, err error) {}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.