File tree Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Expand file tree Collapse file tree 1 file changed +12
-10
lines changed Original file line number Diff line number Diff line change @@ -127,25 +127,27 @@ func (c Client) GetConsumer() (consumer entities.Consumer, err error) {
127
127
// for the current request. While both consumer and credential can be nil,
128
128
// it is required that at least one of them exists. Otherwise this function will throw an error.
129
129
func (c Client ) Authenticate (consumer * entities.Consumer , credential * AuthenticatedCredential ) error {
130
- if consumer == nil {
131
- return fmt .Errorf ("Invalid consumer" )
130
+ if consumer == nil && credential == nil {
131
+ return fmt .Errorf ("either credential or consumer must be provided " )
132
132
}
133
- if credential == nil {
134
- return fmt .Errorf ("Invalid credential" )
135
- }
136
- arg := & kong_plugin_protocol.AuthenticateArgs {
137
- Consumer : & kong_plugin_protocol.Consumer {
133
+
134
+ arg := & kong_plugin_protocol.AuthenticateArgs {}
135
+ if consumer != nil {
136
+ arg .Consumer = & kong_plugin_protocol.Consumer {
138
137
Id : consumer .Id ,
139
138
CreatedAt : int64 (consumer .CreatedAt ),
140
139
Username : consumer .Username ,
141
140
CustomId : consumer .CustomId ,
142
141
Tags : consumer .Tags ,
143
- },
144
- Credential : & kong_plugin_protocol.AuthenticatedCredential {
142
+ }
143
+ }
144
+ if credential != nil {
145
+ arg .Credential = & kong_plugin_protocol.AuthenticatedCredential {
145
146
Id : credential .Id ,
146
147
ConsumerId : credential .ConsumerId ,
147
- },
148
+ }
148
149
}
150
+
149
151
err := c .Ask (`kong.client.authenticate` , arg , nil )
150
152
return err
151
153
}
You can’t perform that action at this time.
0 commit comments