-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvalidate_session.go
More file actions
41 lines (34 loc) · 1.26 KB
/
validate_session.go
File metadata and controls
41 lines (34 loc) · 1.26 KB
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 authorizer
import (
"encoding/json"
"fmt"
)
// ValidateSessionRequest defines attributes for validate_session request
type ValidateSessionRequest struct {
Cookie string `json:"cookie,omitempty"`
Roles []*string `json:"roles,omitempty"`
}
// ValidateSessionInput is deprecated: Use ValidateSessionRequest instead
type ValidateSessionInput = ValidateSessionRequest
// 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.
func (c *AuthorizerClient) ValidateSession(req *ValidateSessionRequest) (*ValidateSessionResponse, error) {
bytesData, err := c.ExecuteGraphQL(&GraphQLRequest{
Query: fmt.Sprintf(`query validateSession($data: ValidateSessionRequest!){validate_session(params: $data) { is_valid user { %s } } }`, UserFragment),
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
}