-
Notifications
You must be signed in to change notification settings - Fork 1
/
client.go
100 lines (82 loc) · 2.16 KB
/
client.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package oauth
import (
"fmt"
"log"
"time"
"github.com/liut/osin-storage/storage"
)
var _ storage.Client = (*Client)(nil)
// Client of oauth2
type Client struct {
ID string `json:"id" db:"id" ` // pk
Secret string `json:"secret" db:"secret"`
RedirectURI string `json:"redirectURI" db:"redirect_uri" `
Meta ClientMeta `json:"meta,omitempty" db:"meta" ` // jsonb
CreatedAt time.Time `json:"created,omitempty" db:"created" ` // time.Now()
}
func (c *Client) String() string {
return fmt.Sprintf("Client{ID: \"%s\" redirectURI: %q meta: %v}", c.ID, c.RedirectURI, c.Meta)
}
// GetId oauth.Client
func (c *Client) GetId() string {
return c.ID
}
// GetSecret oauth.Client
func (c *Client) GetSecret() string {
return c.Secret
}
// GetRedirectUri oauth.Client
func (c *Client) GetRedirectUri() string {
return c.RedirectURI
}
// GetUserData oauth.Client
func (c *Client) GetUserData() interface{} {
return c.Meta
}
// GetName ...
func (c *Client) GetName() string {
return c.Meta.Name
}
// GetGrantTypes ...
func (c *Client) GetGrantTypes() []string {
return c.Meta.GrantTypes
}
// GetResponseTypes ...
func (c *Client) GetResponseTypes() []string {
return c.Meta.ResponseTypes
}
// GetScopes ...
func (c *Client) GetScopes() []string {
return c.Meta.Scopes
}
// CopyFrom ...
func (c *Client) CopyFrom(other storage.Client) {
c.ID = other.GetId()
c.Secret = other.GetSecret()
c.RedirectURI = other.GetRedirectUri()
data := other.GetUserData()
if extra, ok := data.(ClientMeta); ok {
c.Meta = extra
} else {
log.Printf("invalid userData %v", data)
}
}
// NewClient build a client
func NewClient(id, secret, redirectURI string) (c *Client) {
c = &Client{
ID: id,
Secret: secret,
RedirectURI: redirectURI,
CreatedAt: time.Now(),
Meta: defaultClientMeta,
}
return
}
// ClientSpec 查询参数
type ClientSpec struct {
Page int `json:"page,omitempty" form:"page"`
Limit int `json:"limit,omitempty" form:"limit"`
Orders []string `json:"order,omitempty" form:"order"`
Total int `json:"total,omitempty"` // for set value
CountOnly bool `json:"count,omitempty" form:"count"`
}