-
Notifications
You must be signed in to change notification settings - Fork 11
/
connector-tokens.go
41 lines (30 loc) · 1.12 KB
/
connector-tokens.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
package client
import (
"context"
"github.com/Twingate/terraform-provider-twingate/v3/twingate/internal/client/query"
"github.com/Twingate/terraform-provider-twingate/v3/twingate/internal/model"
)
const connectorTokensResourceName = "connector tokens"
func (client *Client) VerifyConnectorTokens(ctx context.Context, refreshToken, accessToken string) error {
payload := map[string]string{
"refresh_token": refreshToken,
}
headers := map[string]string{
"Authorization": "Bearer " + accessToken,
}
_, err := client.post(ctx, "/connector/validate_tokens", payload, headers)
if err != nil {
return NewAPIError(err, "verify", connectorTokensResourceName)
}
return nil
}
func (client *Client) GenerateConnectorTokens(ctx context.Context, connectorID string) (*model.ConnectorTokens, error) {
opr := resourceConnectorToken.generate()
variables := newVars(gqlID(connectorID, "connectorId"))
response := query.GenerateConnectorTokens{}
err := client.mutate(ctx, &response, variables, opr.withCustomName("generateConnectorTokens"), attr{id: connectorID})
if err != nil {
return nil, err
}
return response.ToModel(), nil
}