-
Notifications
You must be signed in to change notification settings - Fork 0
/
auth_validators.go
55 lines (45 loc) · 2.02 KB
/
auth_validators.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
package auth
import (
"github.com/concepts-system/blueprint-service-go/api"
)
// AuthenticationRequestValidator defines the validation rules for a general authentication request.
type AuthenticationRequestValidator struct {
GrantType string `form:"grant_type" query:"grant_type" validate:"required"`
}
// NewAuthenticationRequestValidator returns a new instance of the respective validator.
func NewAuthenticationRequestValidator() AuthenticationRequestValidator {
return AuthenticationRequestValidator{}
}
// PasswordAuthenticationRequestValidator defines the validation rules for an authentication request
// with grant type 'password'.
type PasswordAuthenticationRequestValidator struct {
Username string `form:"username" validate:"required"`
Password string `form:"password" validate:"required"`
}
// Bind binds the API request to the request model.
func (v *AuthenticationRequestValidator) Bind(c api.Context) error {
return c.BindAndValidate(v)
}
// NewPasswordAuthenticationRequestValidator returns a new instance of the respective validator.
func NewPasswordAuthenticationRequestValidator() PasswordAuthenticationRequestValidator {
return PasswordAuthenticationRequestValidator{}
}
// Bind binds the API request to the request model.
func (v *PasswordAuthenticationRequestValidator) Bind(c api.Context) error {
return c.BindAndValidate(v)
}
// RefreshTokenAuthenticationRequestValidator defines the validation rules for an authentication request
// with grant type 'refresh_token'.
type RefreshTokenAuthenticationRequestValidator struct {
Request struct {
RefreshToken string `form:"refresh_token" validate:"required"`
}
}
// NewRefreshTokenAuthenticationRequestValidator returns a new instance of the respective validator.
func NewRefreshTokenAuthenticationRequestValidator() RefreshTokenAuthenticationRequestValidator {
return RefreshTokenAuthenticationRequestValidator{}
}
// Bind binds the API request to the request model.
func (v *RefreshTokenAuthenticationRequestValidator) Bind(c api.Context) error {
return c.BindAndValidate(v)
}