-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
177 lines (154 loc) · 4.28 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
package main
import (
"fmt"
"github.com/apito-cms/buffers/extensions"
"github.com/apito-cms/buffers/protobuff"
"github.com/graphql-go/graphql"
"github.com/labstack/echo/v4"
)
// plugin internal state and implementation
type Authentication struct {
}
// Init system Function Implementation
func (g Authentication) Init(cred *protobuff.ThirdPartyCredential) error {
return nil
}
// Migration system Function Implementation
func (g Authentication) Migration() error {
fmt.Println(fmt.Sprintf("Running Migration with"))
return nil
}
// SchemaRegister system Function Implementation
func (g Authentication) SchemaRegister() (*extensions.ThirdPartyGraphQLSchemas, error) {
fmt.Println(fmt.Sprintf("Running Schema Register with"))
queries := graphql.Fields{}
mutations := graphql.Fields{}
args := graphql.FieldConfigArgument{
"secret": &graphql.ArgumentConfig{
Type: graphql.String,
},
}
args["email"] = &graphql.ArgumentConfig{
Type: graphql.String,
}
queries["loggedInUser"] = &graphql.Field{
Type: graphql.NewObject(graphql.ObjectConfig{
Name: "LoggedInUser",
Fields: graphql.Fields{
"id": &graphql.Field{
Type: graphql.String,
},
"first_name": &graphql.Field{
Type: graphql.String,
},
"email": &graphql.Field{
Type: graphql.String,
},
"phone": &graphql.Field{
Type: graphql.String,
},
"avatar": &graphql.Field{
Type: graphql.String,
},
},
}),
Resolve: g.GetLoggedInUser,
}
queries["login"] = &graphql.Field{
Type: graphql.NewObject(graphql.ObjectConfig{
Name: "UserLogin",
Fields: graphql.Fields{
"id_token": &graphql.Field{
Type: graphql.String,
},
"refresh_token": &graphql.Field{
Type: graphql.String,
},
},
}),
Args: args,
Resolve: g.Login,
}
mutations["register"] = &graphql.Field{
Type: graphql.NewObject(graphql.ObjectConfig{
Name: "UserRegister",
Fields: graphql.Fields{
"id": &graphql.Field{
Type: graphql.String,
},
"id_token": &graphql.Field{
Type: graphql.String,
},
"refresh_token": &graphql.Field{
Type: graphql.String,
},
},
}),
Args: args,
Resolve: g.Register,
}
return &extensions.ThirdPartyGraphQLSchemas{
Queries: queries,
Mutations: mutations,
}, nil
}
// RESTApiRegister system Function Implementation
func (g Authentication) RESTApiRegister() ([]*extensions.ThirdPartyRESTApi, error) {
fmt.Println(fmt.Sprintf("Running REST Api Register with"))
return []*extensions.ThirdPartyRESTApi{
{
Path: "/test",
Method: "GET",
Controller: g.ProviderRegister,
},
}, nil
}
// system Function Implementation
func (g Authentication) ProviderRegister(c echo.Context) error {
return c.JSON(200, map[string]interface{}{
"message": "provider registger",
"code": 200,
})
}
// Register system Function Implementation
func (g Authentication) LoadConfiguration() (map[string]*protobuff.PluginDetails, error) {
fmt.Println("Running Load Configuration")
return map[string]*protobuff.PluginDetails{}, nil
}
// Register system Function Implementation
func (g Authentication) Login(p graphql.ResolveParams) (interface{}, error) {
fmt.Println(fmt.Sprintf("Running Login"))
return map[string]interface{}{
"id_token": "id token",
"refresh_token": "refresh token",
}, nil
}
// Register system Function Implementation
func (g Authentication) Register(p graphql.ResolveParams) (interface{}, error) {
fmt.Println("Running Email Register")
return nil, nil
}
// ForgetPassword system Function Implementation
func (g Authentication) ForgetPassword() {
fmt.Println("Running Register")
}
// SendEmail system Function Implementation
func (g Authentication) SendEmail() {
fmt.Println("Running Register")
}
// SendOTP system Function Implementation
func (g Authentication) SendOTP() {
fmt.Println("Running Register")
}
// GetRegisterUser system Function Implementation
func (g Authentication) GetRegisterUser() {
fmt.Println("Running Register")
}
// GetLoggedInUser system Function Implementation
func (g Authentication) GetLoggedInUser(p graphql.ResolveParams) (interface{}, error) {
fmt.Println(fmt.Sprintf("Running Register"))
return nil, nil
}
// EmailAuth because plugin Name is email-auth exported
// This exported Name is case-sensitive for the extension to load
var EmailAuth Authentication