-
Notifications
You must be signed in to change notification settings - Fork 327
/
oauth2_handler.gen.go
170 lines (143 loc) · 3.38 KB
/
oauth2_handler.gen.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
package automation
// This file is auto-generated.
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
//
// Definitions file that controls how this file is generated:
// automation/automation/oauth2_handler.yaml
import (
"context"
atypes "github.com/cortezaproject/corteza/server/automation/types"
"github.com/cortezaproject/corteza/server/pkg/expr"
"github.com/cortezaproject/corteza/server/pkg/wfexec"
)
var _ wfexec.ExecResponse
type (
oauth2HandlerRegistry interface {
AddFunctions(ff ...*atypes.Function)
Type(ref string) expr.Type
}
)
func (h oauth2Handler) register() {
h.reg.AddFunctions(
h.Authenticate(),
)
}
type (
oauth2AuthenticateArgs struct {
hasClient bool
Client string
hasSecret bool
Secret string
hasScope bool
Scope string
hasTokenUrl bool
TokenUrl string
}
oauth2AuthenticateResults struct {
AccessToken string
RefreshToken string
Token interface{}
}
)
// Authenticate function Authentication: OAUTH2
//
// expects implementation of authenticate function:
// func (h oauth2Handler) authenticate(ctx context.Context, args *oauth2AuthenticateArgs) (results *oauth2AuthenticateResults, err error) {
// return
// }
func (h oauth2Handler) Authenticate() *atypes.Function {
return &atypes.Function{
Ref: "oauth2Authenticate",
Kind: "function",
Labels: map[string]string(nil),
Meta: &atypes.FunctionMeta{
Short: "Authentication: OAUTH2",
},
Parameters: []*atypes.Param{
{
Name: "client",
Types: []string{"String"}, Required: true,
},
{
Name: "secret",
Types: []string{"String"}, Required: true,
},
{
Name: "scope",
Types: []string{"String"}, Required: true,
},
{
Name: "tokenUrl",
Types: []string{"String"}, Required: true,
},
},
Results: []*atypes.Param{
{
Name: "accessToken",
Types: []string{"String"},
},
{
Name: "refreshToken",
Types: []string{"String"},
},
{
Name: "token",
Types: []string{"Any"},
},
},
Handler: func(ctx context.Context, in *expr.Vars) (out *expr.Vars, err error) {
var (
args = &oauth2AuthenticateArgs{
hasClient: in.Has("client"),
hasSecret: in.Has("secret"),
hasScope: in.Has("scope"),
hasTokenUrl: in.Has("tokenUrl"),
}
)
if err = in.Decode(args); err != nil {
return
}
var results *oauth2AuthenticateResults
if results, err = h.authenticate(ctx, args); err != nil {
return
}
out = &expr.Vars{}
{
// converting results.AccessToken (string) to String
var (
tval expr.TypedValue
)
if tval, err = h.reg.Type("String").Cast(results.AccessToken); err != nil {
return
} else if err = expr.Assign(out, "accessToken", tval); err != nil {
return
}
}
{
// converting results.RefreshToken (string) to String
var (
tval expr.TypedValue
)
if tval, err = h.reg.Type("String").Cast(results.RefreshToken); err != nil {
return
} else if err = expr.Assign(out, "refreshToken", tval); err != nil {
return
}
}
{
// converting results.Token (interface{}) to Any
var (
tval expr.TypedValue
)
if tval, err = h.reg.Type("Any").Cast(results.Token); err != nil {
return
} else if err = expr.Assign(out, "token", tval); err != nil {
return
}
}
return
},
}
}