-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviews.go
50 lines (44 loc) · 1.27 KB
/
views.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
package auth
import (
"github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider"
"github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider/types"
"github.com/gin-gonic/gin"
"github.com/go-gorf/gorf"
"github.com/go-gorf/gorf/common"
)
func UserLogin(ctx *gin.Context) {
loginInput := &common.LoginInput{}
err := ctx.Bind(loginInput)
if err != nil {
gorf.BadRequest(ctx, "unable to parse login input", err)
return
}
authInput := &cognitoidentityprovider.InitiateAuthInput{
AuthFlow: types.AuthFlowTypeUserPasswordAuth,
ClientId: &Settings.ClientId,
AuthParameters: map[string]string{
"USERNAME": loginInput.Email,
"PASSWORD": loginInput.Password,
},
}
result, err := client.InitiateAuth(cognitoCtx, authInput)
if err != nil {
gorf.BadRequest(ctx, "failed to authenticate", err)
return
}
gorf.Response(ctx, gin.H{
"TokenType": *result.AuthenticationResult.TokenType,
"ExpiresIn": result.AuthenticationResult.ExpiresIn,
"AccessToken": *result.AuthenticationResult.AccessToken,
"RefreshToken": *result.AuthenticationResult.RefreshToken,
})
//client.RevokeToken()
//client.GetUser()
//client.VerifySoftwareToken()
//client.AssociateSoftwareToken()
}
func ProtectedApi(ctx *gin.Context) {
gorf.Response(ctx, gin.H{
"Status": "ok",
})
}