-
Notifications
You must be signed in to change notification settings - Fork 1
/
validate_session.go
37 lines (30 loc) · 1.17 KB
/
validate_session.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
package authorizer
import "encoding/json"
// ValidateSessionInput defines attributes for validate_session request
type ValidateSessionInput struct {
Cookie string `json:"cookie,omitempty"`
Roles []*string `json:"roles,omitempty"`
}
// ValidateSessionResponse defines attributes for validate_session response
type ValidateSessionResponse struct {
IsValid bool `json:"is_valid"`
User *User `json:"user,omitempty"`
}
// ValidateSession is method attached to AuthorizerClient.
// It performs validate_session query on authorizer instance.
// It returns ValidateSessionResponse reference or error.
// For implementation details check ValidateSessionExample examples/validate_session.go
func (c *AuthorizerClient) ValidateSession(req *ValidateSessionInput) (*ValidateSessionResponse, error) {
bytesData, err := c.ExecuteGraphQL(&GraphQLRequest{
Query: `query validateSession($data: ValidateSessionInput!){validate_session(params: $data) { is_valid user } }`,
Variables: map[string]interface{}{
"data": req,
},
}, nil)
if err != nil {
return nil, err
}
var res map[string]*ValidateSessionResponse
json.Unmarshal(bytesData, &res)
return res["validate_session"], nil
}