parent
f9d2bb8799
commit
e11476364c
|
@ -1,6 +1,10 @@
|
||||||
FROM golang:1.16-alpine as builder
|
FROM golang:1.16-alpine as builder
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY . .
|
COPY . .
|
||||||
|
|
||||||
|
ARG VERSION=0.1.0-beta.0
|
||||||
|
ENV VERSION="${VERSION}"
|
||||||
|
|
||||||
RUN apk add build-base &&\
|
RUN apk add build-base &&\
|
||||||
cd server && \
|
cd server && \
|
||||||
go mod download && \
|
go mod download && \
|
||||||
|
|
|
@ -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.
|
This an [Auth0](https://auth0.com) opensource alternative.
|
||||||
|
|
||||||
|
|
7
server/Makefile
Normal file
7
server/Makefile
Normal 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
|
|
@ -3,6 +3,7 @@ package constants
|
||||||
var (
|
var (
|
||||||
ROOT_SECRET = ""
|
ROOT_SECRET = ""
|
||||||
ENV = ""
|
ENV = ""
|
||||||
|
VERSION = ""
|
||||||
DATABASE_TYPE = ""
|
DATABASE_TYPE = ""
|
||||||
DATABASE_URL = ""
|
DATABASE_URL = ""
|
||||||
SMTP_HOST = ""
|
SMTP_HOST = ""
|
||||||
|
@ -18,6 +19,8 @@ var (
|
||||||
IS_PROD = false
|
IS_PROD = false
|
||||||
COOKIE_NAME = ""
|
COOKIE_NAME = ""
|
||||||
FORGOT_PASSWORD_URI = ""
|
FORGOT_PASSWORD_URI = ""
|
||||||
|
DISABLE_EMAIL_VERICATION = "false"
|
||||||
|
DISABLE_BASIC_AUTHENTICATION = "false"
|
||||||
VERIFY_EMAIL_URI = ""
|
VERIFY_EMAIL_URI = ""
|
||||||
|
|
||||||
// OAuth login
|
// OAuth login
|
||||||
|
|
|
@ -10,6 +10,9 @@ import (
|
||||||
"github.com/joho/godotenv"
|
"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
|
// ParseArgs -> to parse the cli flag and get db url. This is useful with heroku button
|
||||||
func ParseArgs() {
|
func ParseArgs() {
|
||||||
dbURL := flag.String("database_url", "", "Database connection string")
|
dbURL := flag.String("database_url", "", "Database connection string")
|
||||||
|
@ -31,6 +34,8 @@ func InitEnv() {
|
||||||
log.Println("Error loading .env file")
|
log.Println("Error loading .env file")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constants.VERSION = Version
|
||||||
|
|
||||||
constants.ROOT_SECRET = os.Getenv("ROOT_SECRET")
|
constants.ROOT_SECRET = os.Getenv("ROOT_SECRET")
|
||||||
constants.ENV = os.Getenv("ENV")
|
constants.ENV = os.Getenv("ENV")
|
||||||
constants.DATABASE_TYPE = os.Getenv("DATABASE_TYPE")
|
constants.DATABASE_TYPE = os.Getenv("DATABASE_TYPE")
|
||||||
|
@ -56,8 +61,11 @@ func InitEnv() {
|
||||||
constants.TWITTER_CLIENT_SECRET = os.Getenv("TWITTER_CLIENT_SECRET")
|
constants.TWITTER_CLIENT_SECRET = os.Getenv("TWITTER_CLIENT_SECRET")
|
||||||
constants.FORGOT_PASSWORD_URI = strings.TrimPrefix(os.Getenv("FORGOT_PASSWORD_URI"), "/")
|
constants.FORGOT_PASSWORD_URI = strings.TrimPrefix(os.Getenv("FORGOT_PASSWORD_URI"), "/")
|
||||||
constants.VERIFY_EMAIL_URI = strings.TrimPrefix(os.Getenv("VERIFY_EMAIL_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 == "" {
|
if constants.ROOT_SECRET == "" {
|
||||||
panic("Root admin secret is required")
|
panic("root admin secret is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
if constants.ENV == "" {
|
if constants.ENV == "" {
|
||||||
|
@ -91,4 +99,16 @@ func InitEnv() {
|
||||||
if constants.SERVER_URL == "" {
|
if constants.SERVER_URL == "" {
|
||||||
constants.SERVER_URL = "http://localhost:8080"
|
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,6 +55,16 @@ type ComplexityRoot struct {
|
||||||
User func(childComplexity int) int
|
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 {
|
Mutation struct {
|
||||||
ForgotPassword func(childComplexity int, params model.ForgotPasswordInput) int
|
ForgotPassword func(childComplexity int, params model.ForgotPasswordInput) int
|
||||||
Login func(childComplexity int, params model.LoginInput) int
|
Login func(childComplexity int, params model.LoginInput) int
|
||||||
|
@ -67,6 +77,7 @@ type ComplexityRoot struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
Query struct {
|
Query struct {
|
||||||
|
Meta func(childComplexity int) int
|
||||||
Profile func(childComplexity int) int
|
Profile func(childComplexity int) int
|
||||||
Token func(childComplexity int) int
|
Token func(childComplexity int) int
|
||||||
Users 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)
|
ResetPassword(ctx context.Context, params model.ResetPassowrdInput) (*model.Response, error)
|
||||||
}
|
}
|
||||||
type QueryResolver interface {
|
type QueryResolver interface {
|
||||||
|
Meta(ctx context.Context) (*model.Meta, error)
|
||||||
Users(ctx context.Context) ([]*model.User, error)
|
Users(ctx context.Context) ([]*model.User, error)
|
||||||
Token(ctx context.Context) (*model.LoginResponse, error)
|
Token(ctx context.Context) (*model.LoginResponse, error)
|
||||||
Profile(ctx context.Context) (*model.User, 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
|
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":
|
case "Mutation.forgotPassword":
|
||||||
if e.complexity.Mutation.ForgotPassword == nil {
|
if e.complexity.Mutation.ForgotPassword == nil {
|
||||||
break
|
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
|
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":
|
case "Query.profile":
|
||||||
if e.complexity.Query.Profile == nil {
|
if e.complexity.Query.Profile == nil {
|
||||||
break
|
break
|
||||||
|
@ -481,6 +549,16 @@ var sources = []*ast.Source{
|
||||||
# https://gqlgen.com/getting-started/
|
# https://gqlgen.com/getting-started/
|
||||||
scalar Int64
|
scalar Int64
|
||||||
|
|
||||||
|
type Meta {
|
||||||
|
version: String!
|
||||||
|
isGoogleLoginEnabled: Boolean!
|
||||||
|
isFacebookLoginEnabled: Boolean!
|
||||||
|
isTwitterLoginEnabled: Boolean!
|
||||||
|
isGithubLoginEnabled: Boolean!
|
||||||
|
isEmailVerificationEnabled: Boolean!
|
||||||
|
isBasicAuthenticationEnabled: Boolean!
|
||||||
|
}
|
||||||
|
|
||||||
type User {
|
type User {
|
||||||
id: ID!
|
id: ID!
|
||||||
email: String!
|
email: String!
|
||||||
|
@ -573,6 +651,7 @@ type Mutation {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Query {
|
type Query {
|
||||||
|
meta: Meta!
|
||||||
users: [User!]!
|
users: [User!]!
|
||||||
token: LoginResponse
|
token: LoginResponse
|
||||||
profile: User!
|
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)
|
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) {
|
func (ec *executionContext) _Mutation_signup(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
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)
|
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) {
|
func (ec *executionContext) _Query_users(ctx context.Context, field graphql.CollectedField) (ret graphql.Marshaler) {
|
||||||
defer func() {
|
defer func() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
|
@ -3453,6 +3812,63 @@ func (ec *executionContext) _LoginResponse(ctx context.Context, sel ast.Selectio
|
||||||
return out
|
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"}
|
var mutationImplementors = []string{"Mutation"}
|
||||||
|
|
||||||
func (ec *executionContext) _Mutation(ctx context.Context, sel ast.SelectionSet) graphql.Marshaler {
|
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 {
|
switch field.Name {
|
||||||
case "__typename":
|
case "__typename":
|
||||||
out.Values[i] = graphql.MarshalString("Query")
|
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":
|
case "users":
|
||||||
field := field
|
field := field
|
||||||
out.Concurrently(i, func() (res graphql.Marshaler) {
|
out.Concurrently(i, func() (res graphql.Marshaler) {
|
||||||
|
@ -4016,6 +4446,20 @@ func (ec *executionContext) marshalNLoginResponse2ᚖgithubᚗcomᚋauthorizerde
|
||||||
return ec._LoginResponse(ctx, sel, v)
|
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) {
|
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)
|
res, err := ec.unmarshalInputResendVerifyEmailInput(ctx, v)
|
||||||
return res, graphql.ErrorOnPath(ctx, err)
|
return res, graphql.ErrorOnPath(ctx, err)
|
||||||
|
|
|
@ -23,6 +23,16 @@ type LoginResponse struct {
|
||||||
User *User `json:"user"`
|
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 {
|
type ResendVerifyEmailInput struct {
|
||||||
Email string `json:"email"`
|
Email string `json:"email"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,16 @@
|
||||||
# https://gqlgen.com/getting-started/
|
# https://gqlgen.com/getting-started/
|
||||||
scalar Int64
|
scalar Int64
|
||||||
|
|
||||||
|
type Meta {
|
||||||
|
version: String!
|
||||||
|
isGoogleLoginEnabled: Boolean!
|
||||||
|
isFacebookLoginEnabled: Boolean!
|
||||||
|
isTwitterLoginEnabled: Boolean!
|
||||||
|
isGithubLoginEnabled: Boolean!
|
||||||
|
isEmailVerificationEnabled: Boolean!
|
||||||
|
isBasicAuthenticationEnabled: Boolean!
|
||||||
|
}
|
||||||
|
|
||||||
type User {
|
type User {
|
||||||
id: ID!
|
id: ID!
|
||||||
email: String!
|
email: String!
|
||||||
|
@ -95,6 +105,7 @@ type Mutation {
|
||||||
}
|
}
|
||||||
|
|
||||||
type Query {
|
type Query {
|
||||||
|
meta: Meta!
|
||||||
users: [User!]!
|
users: [User!]!
|
||||||
token: LoginResponse
|
token: LoginResponse
|
||||||
profile: User!
|
profile: User!
|
||||||
|
|
|
@ -43,6 +43,10 @@ func (r *mutationResolver) ResetPassword(ctx context.Context, params model.Reset
|
||||||
return resolvers.ResetPassword(ctx, params)
|
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) {
|
func (r *queryResolver) Users(ctx context.Context) ([]*model.User, error) {
|
||||||
return resolvers.Users(ctx)
|
return resolvers.Users(ctx)
|
||||||
}
|
}
|
||||||
|
|
13
server/resolvers/meta.go
Normal file
13
server/resolvers/meta.go
Normal 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
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ package resolvers
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/authorizerdev/authorizer/server/db"
|
"github.com/authorizerdev/authorizer/server/db"
|
||||||
|
@ -13,8 +14,11 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func Token(ctx context.Context) (*model.LoginResponse, error) {
|
func Token(ctx context.Context) (*model.LoginResponse, error) {
|
||||||
gc, err := utils.GinContextFromContext(ctx)
|
metaInfo := utils.GetMetaInfo()
|
||||||
|
log.Println("=> meta", metaInfo)
|
||||||
var res *model.LoginResponse
|
var res *model.LoginResponse
|
||||||
|
|
||||||
|
gc, err := utils.GinContextFromContext(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return res, err
|
return res, err
|
||||||
}
|
}
|
||||||
|
@ -52,7 +56,7 @@ func Token(ctx context.Context) (*model.LoginResponse, error) {
|
||||||
}
|
}
|
||||||
utils.SetCookie(gc, token)
|
utils.SetCookie(gc, token)
|
||||||
res = &model.LoginResponse{
|
res = &model.LoginResponse{
|
||||||
Message: `Email verified successfully.`,
|
Message: `Token verified`,
|
||||||
AccessToken: &token,
|
AccessToken: &token,
|
||||||
AccessTokenExpiresAt: &expiresAt,
|
AccessTokenExpiresAt: &expiresAt,
|
||||||
User: &model.User{
|
User: &model.User{
|
||||||
|
|
|
@ -55,7 +55,7 @@ func GetAuthToken(gc *gin.Context) (string, error) {
|
||||||
log.Println("cookie not found checking headers")
|
log.Println("cookie not found checking headers")
|
||||||
auth := gc.Request.Header.Get("Authorization")
|
auth := gc.Request.Header.Get("Authorization")
|
||||||
if auth == "" {
|
if auth == "" {
|
||||||
return "", fmt.Errorf(`Unauthorized`)
|
return "", fmt.Errorf(`unauthorized`)
|
||||||
}
|
}
|
||||||
|
|
||||||
token = strings.TrimPrefix(auth, "Bearer ")
|
token = strings.TrimPrefix(auth, "Bearer ")
|
||||||
|
|
20
server/utils/meta.go
Normal file
20
server/utils/meta.go
Normal 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",
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user