feat/add meta query (#38)

* feat: add meta query

* fix: readme
This commit is contained in:
Lakhan Samani 2021-07-28 13:25:52 +05:30 committed by GitHub
parent f9d2bb8799
commit e11476364c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 564 additions and 24 deletions

View File

@ -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 && \

View File

@ -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.

7
server/Makefile Normal file
View File

@ -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

View File

@ -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 = ""

View File

@ -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"
}
}
}

View File

@ -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)

View File

@ -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"`
}

View File

@ -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!

View File

@ -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)
}

13
server/resolvers/meta.go Normal file
View File

@ -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
}

View File

@ -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{

View File

@ -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 ")

20
server/utils/meta.go Normal file
View File

@ -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",
}
}