From e11476364c962173bcf0d748304fe04711b90e70 Mon Sep 17 00:00:00 2001 From: Lakhan Samani Date: Wed, 28 Jul 2021 13:25:52 +0530 Subject: [PATCH] feat/add meta query (#38) * feat: add meta query * fix: readme --- Dockerfile | 4 + README.md | 4 +- server/Makefile | 7 + server/constants/constants.go | 39 +-- server/env.go | 22 +- server/graph/generated/generated.go | 444 ++++++++++++++++++++++++++++ server/graph/model/models_gen.go | 10 + server/graph/schema.graphqls | 11 + server/graph/schema.resolvers.go | 4 + server/resolvers/meta.go | 13 + server/resolvers/token.go | 8 +- server/utils/authToken.go | 2 +- server/utils/meta.go | 20 ++ 13 files changed, 564 insertions(+), 24 deletions(-) create mode 100644 server/Makefile create mode 100644 server/resolvers/meta.go create mode 100644 server/utils/meta.go diff --git a/Dockerfile b/Dockerfile index 57f3618..d1d3a17 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,10 @@ FROM golang:1.16-alpine as builder WORKDIR /app COPY . . + +ARG VERSION=0.1.0-beta.0 +ENV VERSION="${VERSION}" + RUN apk add build-base &&\ cd server && \ go mod download && \ diff --git a/README.md b/README.md index b67adc1..d4896cd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -#authorizer +# authorizer -authorizer (aka your-auth) is a complete open source authentication and authorization solution for your applications. Bring your database and have complete control over the authentication, authorization and user data. It is a microservice that can be deployed anywhere and connected any sql database. +authorizer is a complete open source authentication and authorization solution for your applications. Bring your database and have complete control over the authentication, authorization and user data. It is a microservice that can be deployed anywhere and connected any sql database. This an [Auth0](https://auth0.com) opensource alternative. diff --git a/server/Makefile b/server/Makefile new file mode 100644 index 0000000..f7359dd --- /dev/null +++ b/server/Makefile @@ -0,0 +1,7 @@ +DEFAULT_VERSION=0.1.0-local +VERSION := $(or $(VERSION),$(DEFAULT_VERSION)) + +cmd: + go build -ldflags "-w -X main.Version=$(VERSION)" +clean: + rm -rf server \ No newline at end of file diff --git a/server/constants/constants.go b/server/constants/constants.go index 68a8495..73d6b42 100644 --- a/server/constants/constants.go +++ b/server/constants/constants.go @@ -1,24 +1,27 @@ package constants var ( - ROOT_SECRET = "" - ENV = "" - DATABASE_TYPE = "" - DATABASE_URL = "" - SMTP_HOST = "" - SMTP_PORT = "" - SENDER_EMAIL = "" - SENDER_PASSWORD = "" - JWT_TYPE = "" - JWT_SECRET = "" - FRONTEND_URL = "" - SERVER_URL = "" - PORT = "8080" - REDIS_URL = "" - IS_PROD = false - COOKIE_NAME = "" - FORGOT_PASSWORD_URI = "" - VERIFY_EMAIL_URI = "" + ROOT_SECRET = "" + ENV = "" + VERSION = "" + DATABASE_TYPE = "" + DATABASE_URL = "" + SMTP_HOST = "" + SMTP_PORT = "" + SENDER_EMAIL = "" + SENDER_PASSWORD = "" + JWT_TYPE = "" + JWT_SECRET = "" + FRONTEND_URL = "" + SERVER_URL = "" + PORT = "8080" + REDIS_URL = "" + IS_PROD = false + COOKIE_NAME = "" + FORGOT_PASSWORD_URI = "" + DISABLE_EMAIL_VERICATION = "false" + DISABLE_BASIC_AUTHENTICATION = "false" + VERIFY_EMAIL_URI = "" // OAuth login GOOGLE_CLIENT_ID = "" diff --git a/server/env.go b/server/env.go index 7f3d377..45825e0 100644 --- a/server/env.go +++ b/server/env.go @@ -10,6 +10,9 @@ import ( "github.com/joho/godotenv" ) +// build variables +var Version string + // ParseArgs -> to parse the cli flag and get db url. This is useful with heroku button func ParseArgs() { dbURL := flag.String("database_url", "", "Database connection string") @@ -31,6 +34,8 @@ func InitEnv() { log.Println("Error loading .env file") } + constants.VERSION = Version + constants.ROOT_SECRET = os.Getenv("ROOT_SECRET") constants.ENV = os.Getenv("ENV") constants.DATABASE_TYPE = os.Getenv("DATABASE_TYPE") @@ -56,8 +61,11 @@ func InitEnv() { constants.TWITTER_CLIENT_SECRET = os.Getenv("TWITTER_CLIENT_SECRET") constants.FORGOT_PASSWORD_URI = strings.TrimPrefix(os.Getenv("FORGOT_PASSWORD_URI"), "/") constants.VERIFY_EMAIL_URI = strings.TrimPrefix(os.Getenv("VERIFY_EMAIL_URI"), "/") + constants.DISABLE_BASIC_AUTHENTICATION = os.Getenv("DISABLE_BASIC_AUTHENTICATION") + constants.DISABLE_EMAIL_VERICATION = os.Getenv("DISABLE_EMAIL_VERICATION") + if constants.ROOT_SECRET == "" { - panic("Root admin secret is required") + panic("root admin secret is required") } if constants.ENV == "" { @@ -91,4 +99,16 @@ func InitEnv() { if constants.SERVER_URL == "" { constants.SERVER_URL = "http://localhost:8080" } + + if constants.DISABLE_BASIC_AUTHENTICATION == "" { + constants.DISABLE_BASIC_AUTHENTICATION = "false" + } + + if constants.DISABLE_EMAIL_VERICATION == "" && constants.DISABLE_BASIC_AUTHENTICATION == "false" { + if constants.SMTP_HOST == "" || constants.SENDER_EMAIL == "" || constants.SENDER_PASSWORD == "" { + constants.DISABLE_EMAIL_VERICATION = "true" + } else { + constants.DISABLE_EMAIL_VERICATION = "false" + } + } } diff --git a/server/graph/generated/generated.go b/server/graph/generated/generated.go index 444de40..6fd8fc4 100644 --- a/server/graph/generated/generated.go +++ b/server/graph/generated/generated.go @@ -55,6 +55,16 @@ type ComplexityRoot struct { User func(childComplexity int) int } + Meta struct { + IsBasicAuthenticationEnabled func(childComplexity int) int + IsEmailVerificationEnabled func(childComplexity int) int + IsFacebookLoginEnabled func(childComplexity int) int + IsGithubLoginEnabled func(childComplexity int) int + IsGoogleLoginEnabled func(childComplexity int) int + IsTwitterLoginEnabled func(childComplexity int) int + Version func(childComplexity int) int + } + Mutation struct { ForgotPassword func(childComplexity int, params model.ForgotPasswordInput) int Login func(childComplexity int, params model.LoginInput) int @@ -67,6 +77,7 @@ type ComplexityRoot struct { } Query struct { + Meta func(childComplexity int) int Profile func(childComplexity int) int Token func(childComplexity int) int Users func(childComplexity int) int @@ -111,6 +122,7 @@ type MutationResolver interface { ResetPassword(ctx context.Context, params model.ResetPassowrdInput) (*model.Response, error) } type QueryResolver interface { + Meta(ctx context.Context) (*model.Meta, error) Users(ctx context.Context) ([]*model.User, error) Token(ctx context.Context) (*model.LoginResponse, error) Profile(ctx context.Context) (*model.User, error) @@ -174,6 +186,55 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.LoginResponse.User(childComplexity), true + case "Meta.isBasicAuthenticationEnabled": + if e.complexity.Meta.IsBasicAuthenticationEnabled == nil { + break + } + + return e.complexity.Meta.IsBasicAuthenticationEnabled(childComplexity), true + + case "Meta.isEmailVerificationEnabled": + if e.complexity.Meta.IsEmailVerificationEnabled == nil { + break + } + + return e.complexity.Meta.IsEmailVerificationEnabled(childComplexity), true + + case "Meta.isFacebookLoginEnabled": + if e.complexity.Meta.IsFacebookLoginEnabled == nil { + break + } + + return e.complexity.Meta.IsFacebookLoginEnabled(childComplexity), true + + case "Meta.isGithubLoginEnabled": + if e.complexity.Meta.IsGithubLoginEnabled == nil { + break + } + + return e.complexity.Meta.IsGithubLoginEnabled(childComplexity), true + + case "Meta.isGoogleLoginEnabled": + if e.complexity.Meta.IsGoogleLoginEnabled == nil { + break + } + + return e.complexity.Meta.IsGoogleLoginEnabled(childComplexity), true + + case "Meta.isTwitterLoginEnabled": + if e.complexity.Meta.IsTwitterLoginEnabled == nil { + break + } + + return e.complexity.Meta.IsTwitterLoginEnabled(childComplexity), true + + case "Meta.version": + if e.complexity.Meta.Version == nil { + break + } + + return e.complexity.Meta.Version(childComplexity), true + case "Mutation.forgotPassword": if e.complexity.Mutation.ForgotPassword == nil { break @@ -265,6 +326,13 @@ func (e *executableSchema) Complexity(typeName, field string, childComplexity in return e.complexity.Mutation.VerifyEmail(childComplexity, args["params"].(model.VerifyEmailInput)), true + case "Query.meta": + if e.complexity.Query.Meta == nil { + break + } + + return e.complexity.Query.Meta(childComplexity), true + case "Query.profile": if e.complexity.Query.Profile == nil { break @@ -481,6 +549,16 @@ var sources = []*ast.Source{ # https://gqlgen.com/getting-started/ scalar Int64 +type Meta { + version: String! + isGoogleLoginEnabled: Boolean! + isFacebookLoginEnabled: Boolean! + isTwitterLoginEnabled: Boolean! + isGithubLoginEnabled: Boolean! + isEmailVerificationEnabled: Boolean! + isBasicAuthenticationEnabled: Boolean! +} + type User { id: ID! email: String! @@ -573,6 +651,7 @@ type Mutation { } type Query { + meta: Meta! users: [User!]! token: LoginResponse profile: User! @@ -945,6 +1024,251 @@ func (ec *executionContext) _LoginResponse_user(ctx context.Context, field graph return ec.marshalOUser2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐUser(ctx, field.Selections, res) } +func (ec *executionContext) _Meta_version(ctx context.Context, field graphql.CollectedField, obj *model.Meta) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Meta", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.Version, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(string) + fc.Result = res + return ec.marshalNString2string(ctx, field.Selections, res) +} + +func (ec *executionContext) _Meta_isGoogleLoginEnabled(ctx context.Context, field graphql.CollectedField, obj *model.Meta) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Meta", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsGoogleLoginEnabled, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) _Meta_isFacebookLoginEnabled(ctx context.Context, field graphql.CollectedField, obj *model.Meta) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Meta", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsFacebookLoginEnabled, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) _Meta_isTwitterLoginEnabled(ctx context.Context, field graphql.CollectedField, obj *model.Meta) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Meta", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsTwitterLoginEnabled, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) _Meta_isGithubLoginEnabled(ctx context.Context, field graphql.CollectedField, obj *model.Meta) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Meta", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsGithubLoginEnabled, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) _Meta_isEmailVerificationEnabled(ctx context.Context, field graphql.CollectedField, obj *model.Meta) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Meta", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsEmailVerificationEnabled, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + +func (ec *executionContext) _Meta_isBasicAuthenticationEnabled(ctx context.Context, field graphql.CollectedField, obj *model.Meta) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Meta", + Field: field, + Args: nil, + IsMethod: false, + IsResolver: false, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return obj.IsBasicAuthenticationEnabled, nil + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(bool) + fc.Result = res + return ec.marshalNBoolean2bool(ctx, field.Selections, res) +} + func (ec *executionContext) _Mutation_signup(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -1274,6 +1598,41 @@ func (ec *executionContext) _Mutation_resetPassword(ctx context.Context, field g return ec.marshalNResponse2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐResponse(ctx, field.Selections, res) } +func (ec *executionContext) _Query_meta(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + ret = graphql.Null + } + }() + fc := &graphql.FieldContext{ + Object: "Query", + Field: field, + Args: nil, + IsMethod: true, + IsResolver: true, + } + + ctx = graphql.WithFieldContext(ctx, fc) + resTmp, err := ec.ResolverMiddleware(ctx, func(rctx context.Context) (interface{}, error) { + ctx = rctx // use context from middleware stack in children + return ec.resolvers.Query().Meta(rctx) + }) + if err != nil { + ec.Error(ctx, err) + return graphql.Null + } + if resTmp == nil { + if !graphql.HasFieldError(ctx, fc) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + res := resTmp.(*model.Meta) + fc.Result = res + return ec.marshalNMeta2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐMeta(ctx, field.Selections, res) +} + func (ec *executionContext) _Query_users(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) { defer func() { if r := recover(); r != nil { @@ -3453,6 +3812,63 @@ func (ec *executionContext) _LoginResponse(ctx context.Context, sel ast.Selectio return out } +var metaImplementors = []string{"Meta"} + +func (ec *executionContext) _Meta(ctx context.Context, sel ast.SelectionSet, obj *model.Meta) graphql.Marshaler { + fields := graphql.CollectFields(ec.OperationContext, sel, metaImplementors) + + out := graphql.NewFieldSet(fields) + var invalids uint32 + for i, field := range fields { + switch field.Name { + case "__typename": + out.Values[i] = graphql.MarshalString("Meta") + case "version": + out.Values[i] = ec._Meta_version(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "isGoogleLoginEnabled": + out.Values[i] = ec._Meta_isGoogleLoginEnabled(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "isFacebookLoginEnabled": + out.Values[i] = ec._Meta_isFacebookLoginEnabled(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "isTwitterLoginEnabled": + out.Values[i] = ec._Meta_isTwitterLoginEnabled(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "isGithubLoginEnabled": + out.Values[i] = ec._Meta_isGithubLoginEnabled(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "isEmailVerificationEnabled": + out.Values[i] = ec._Meta_isEmailVerificationEnabled(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + case "isBasicAuthenticationEnabled": + out.Values[i] = ec._Meta_isBasicAuthenticationEnabled(ctx, field, obj) + if out.Values[i] == graphql.Null { + invalids++ + } + default: + panic("unknown field " + strconv.Quote(field.Name)) + } + } + out.Dispatch() + if invalids > 0 { + return graphql.Null + } + return out +} + var mutationImplementors = []string{"Mutation"} func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler { @@ -3534,6 +3950,20 @@ func (ec *executionContext) _Query(ctx context.Context, sel ast.SelectionSet) gr switch field.Name { case "__typename": out.Values[i] = graphql.MarshalString("Query") + case "meta": + field := field + out.Concurrently(i, func() (res graphql.Marshaler) { + defer func() { + if r := recover(); r != nil { + ec.Error(ctx, ec.Recover(ctx, r)) + } + }() + res = ec._Query_meta(ctx, field) + if res == graphql.Null { + atomic.AddUint32(&invalids, 1) + } + return res + }) case "users": field := field out.Concurrently(i, func() (res graphql.Marshaler) { @@ -4016,6 +4446,20 @@ func (ec *executionContext) marshalNLoginResponse2ᚖgithubᚗcomᚋauthorizerde return ec._LoginResponse(ctx, sel, v) } +func (ec *executionContext) marshalNMeta2githubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐMeta(ctx context.Context, sel ast.SelectionSet, v model.Meta) graphql.Marshaler { + return ec._Meta(ctx, sel, &v) +} + +func (ec *executionContext) marshalNMeta2ᚖgithubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐMeta(ctx context.Context, sel ast.SelectionSet, v *model.Meta) graphql.Marshaler { + if v == nil { + if !graphql.HasFieldError(ctx, graphql.GetFieldContext(ctx)) { + ec.Errorf(ctx, "must not be null") + } + return graphql.Null + } + return ec._Meta(ctx, sel, v) +} + func (ec *executionContext) unmarshalNResendVerifyEmailInput2githubᚗcomᚋauthorizerdevᚋauthorizerᚋserverᚋgraphᚋmodelᚐResendVerifyEmailInput(ctx context.Context, v interface{}) (model.ResendVerifyEmailInput, error) { res, err := ec.unmarshalInputResendVerifyEmailInput(ctx, v) return res, graphql.ErrorOnPath(ctx, err) diff --git a/server/graph/model/models_gen.go b/server/graph/model/models_gen.go index 11aeb68..7121e2a 100644 --- a/server/graph/model/models_gen.go +++ b/server/graph/model/models_gen.go @@ -23,6 +23,16 @@ type LoginResponse struct { User *User `json:"user"` } +type Meta struct { + Version string `json:"version"` + IsGoogleLoginEnabled bool `json:"isGoogleLoginEnabled"` + IsFacebookLoginEnabled bool `json:"isFacebookLoginEnabled"` + IsTwitterLoginEnabled bool `json:"isTwitterLoginEnabled"` + IsGithubLoginEnabled bool `json:"isGithubLoginEnabled"` + IsEmailVerificationEnabled bool `json:"isEmailVerificationEnabled"` + IsBasicAuthenticationEnabled bool `json:"isBasicAuthenticationEnabled"` +} + type ResendVerifyEmailInput struct { Email string `json:"email"` } diff --git a/server/graph/schema.graphqls b/server/graph/schema.graphqls index a0b7cce..ba5d5aa 100644 --- a/server/graph/schema.graphqls +++ b/server/graph/schema.graphqls @@ -3,6 +3,16 @@ # https://gqlgen.com/getting-started/ scalar Int64 +type Meta { + version: String! + isGoogleLoginEnabled: Boolean! + isFacebookLoginEnabled: Boolean! + isTwitterLoginEnabled: Boolean! + isGithubLoginEnabled: Boolean! + isEmailVerificationEnabled: Boolean! + isBasicAuthenticationEnabled: Boolean! +} + type User { id: ID! email: String! @@ -95,6 +105,7 @@ type Mutation { } type Query { + meta: Meta! users: [User!]! token: LoginResponse profile: User! diff --git a/server/graph/schema.resolvers.go b/server/graph/schema.resolvers.go index 6661b6b..1e1b4f5 100644 --- a/server/graph/schema.resolvers.go +++ b/server/graph/schema.resolvers.go @@ -43,6 +43,10 @@ func (r *mutationResolver) ResetPassword(ctx context.Context, params model.Reset return resolvers.ResetPassword(ctx, params) } +func (r *queryResolver) Meta(ctx context.Context) (*model.Meta, error) { + return resolvers.Meta(ctx) +} + func (r *queryResolver) Users(ctx context.Context) ([]*model.User, error) { return resolvers.Users(ctx) } diff --git a/server/resolvers/meta.go b/server/resolvers/meta.go new file mode 100644 index 0000000..9873ab6 --- /dev/null +++ b/server/resolvers/meta.go @@ -0,0 +1,13 @@ +package resolvers + +import ( + "context" + + "github.com/authorizerdev/authorizer/server/graph/model" + "github.com/authorizerdev/authorizer/server/utils" +) + +func Meta(ctx context.Context) (*model.Meta, error) { + metaInfo := utils.GetMetaInfo() + return &metaInfo, nil +} diff --git a/server/resolvers/token.go b/server/resolvers/token.go index 67bda13..80679dd 100644 --- a/server/resolvers/token.go +++ b/server/resolvers/token.go @@ -3,6 +3,7 @@ package resolvers import ( "context" "fmt" + "log" "time" "github.com/authorizerdev/authorizer/server/db" @@ -13,8 +14,11 @@ import ( ) func Token(ctx context.Context) (*model.LoginResponse, error) { - gc, err := utils.GinContextFromContext(ctx) + metaInfo := utils.GetMetaInfo() + log.Println("=> meta", metaInfo) var res *model.LoginResponse + + gc, err := utils.GinContextFromContext(ctx) if err != nil { return res, err } @@ -52,7 +56,7 @@ func Token(ctx context.Context) (*model.LoginResponse, error) { } utils.SetCookie(gc, token) res = &model.LoginResponse{ - Message: `Email verified successfully.`, + Message: `Token verified`, AccessToken: &token, AccessTokenExpiresAt: &expiresAt, User: &model.User{ diff --git a/server/utils/authToken.go b/server/utils/authToken.go index 44af5c4..0ce6b67 100644 --- a/server/utils/authToken.go +++ b/server/utils/authToken.go @@ -55,7 +55,7 @@ func GetAuthToken(gc *gin.Context) (string, error) { log.Println("cookie not found checking headers") auth := gc.Request.Header.Get("Authorization") if auth == "" { - return "", fmt.Errorf(`Unauthorized`) + return "", fmt.Errorf(`unauthorized`) } token = strings.TrimPrefix(auth, "Bearer ") diff --git a/server/utils/meta.go b/server/utils/meta.go new file mode 100644 index 0000000..1936510 --- /dev/null +++ b/server/utils/meta.go @@ -0,0 +1,20 @@ +package utils + +import ( + "github.com/authorizerdev/authorizer/server/constants" + "github.com/authorizerdev/authorizer/server/graph/model" +) + +// GetMeta helps in getting the meta data about the deployment +// version, +func GetMetaInfo() model.Meta { + return model.Meta{ + Version: constants.VERSION, + IsGoogleLoginEnabled: constants.GOOGLE_CLIENT_ID != "" && constants.GOOGLE_CLIENT_SECRET != "", + IsGithubLoginEnabled: constants.GITHUB_CLIENT_ID != "" && constants.GOOGLE_CLIENT_SECRET != "", + IsFacebookLoginEnabled: constants.FACEBOOK_CLIENT_ID != "" && constants.FACEBOOK_CLIENT_SECRET != "", + IsTwitterLoginEnabled: constants.TWITTER_CLIENT_ID != "" && constants.TWITTER_CLIENT_SECRET != "", + IsBasicAuthenticationEnabled: constants.DISABLE_BASIC_AUTHENTICATION != "false", + IsEmailVerificationEnabled: constants.DISABLE_EMAIL_VERICATION != "false", + } +}