-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.go
72 lines (61 loc) · 2.39 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
package client
import (
"strings"
"github.com/ory-am/fosite"
)
type Client struct {
ID string `json:"id" gorethink:"id"`
Name string `json:"client_name" gorethink:"client_name"`
Secret string `json:"client_secret,omitempty" gorethink:"client_secret"`
RedirectURIs []string `json:"redirect_uris" gorethink:"redirect_uris"`
GrantTypes []string `json:"grant_types" gorethink:"grant_types"`
ResponseTypes []string `json:"response_types" gorethink:"response_types"`
Scope string `json:"scope" gorethink:"scope"`
Owner string `json:"owner" gorethink:"owner"`
PolicyURI string `json:"policy_uri" gorethink:"policy_uri"`
TermsOfServiceURI string `json:"tos_uri" gorethink:"tos_uri"`
ClientURI string `json:"client_uri" gorethink:"client_uri"`
LogoURI string `json:"logo_uri" gorethink:"logo_uri"`
Contacts []string `json:"contacts" gorethink:"contacts"`
Public bool `json:"public" gorethink:"public"`
}
func (c *Client) GetID() string {
return c.ID
}
func (c *Client) GetRedirectURIs() []string {
return c.RedirectURIs
}
func (c *Client) GetHashedSecret() []byte {
return []byte(c.Secret)
}
func (c *Client) GetScopes() fosite.Arguments {
return fosite.Arguments(strings.Split(c.Scope, " "))
}
func (c *Client) GetGrantTypes() fosite.Arguments {
// https://openid.net/specs/openid-connect-registration-1_0.html#ClientMetadata
//
// JSON array containing a list of the OAuth 2.0 Grant Types that the Client is declaring
// that it will restrict itself to using.
// If omitted, the default is that the Client will use only the authorization_code Grant Type.
if len(c.GrantTypes) == 0 {
return fosite.Arguments{"authorization_code"}
}
return fosite.Arguments(c.GrantTypes)
}
func (c *Client) GetResponseTypes() fosite.Arguments {
// https://openid.net/specs/openid-connect-registration-1_0.html#ClientMetadata
//
// <JSON array containing a list of the OAuth 2.0 response_type values that the Client is declaring
// that it will restrict itself to using. If omitted, the default is that the Client will use
// only the code Response Type.
if len(c.ResponseTypes) == 0 {
return fosite.Arguments{"code"}
}
return fosite.Arguments(c.ResponseTypes)
}
func (c *Client) GetOwner() string {
return c.Owner
}
func (c *Client) IsPublic() bool {
return c.Public
}