-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
51 lines (40 loc) · 1013 Bytes
/
main.go
File metadata and controls
51 lines (40 loc) · 1013 Bytes
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
package main
import (
"encoding/json"
"github.com/aws/aws-lambda-go/events"
"github.com/aws/aws-lambda-go/lambda"
)
func main() {
lambda.Start(handler)
}
func handler(request events.APIGatewayProxyRequest) (events.APIGatewayProxyResponse, error) {
var apidata ApiData
err := json.Unmarshal([]byte(request.Body), &apidata)
if err != nil {
return events.APIGatewayProxyResponse{}, err
}
var requestParams = AuthorizationConfig{
Code: apidata.Code,
RedirectURI: apidata.RedirectURI,
GrantType: apidata.GrantType,
}
_token, err := GetTokens(requestParams)
if err != nil {
panic(err)
}
ResponseData := Tokens{
AccessToken: _token.AccessToken,
RefreshToken: _token.RefreshToken,
Expiry: _token.Expiry,
}
aJson, err := json.Marshal(ResponseData)
if err != nil {
panic(err)
}
response := events.APIGatewayProxyResponse{
StatusCode: 200,
Body: string(aJson),
Headers: map[string]string{"Tocrocon-Version": version},
}
return response, nil
}