...
1 package client
2
3 import (
4 "context"
5
6 "github.com/ory/fosite"
7 )
8
9
10 type Client struct {
11 ID string
12 Profile *Profile
13 Credentials *Credentials
14 }
15
16
17 type Credentials struct {
18 Secret string
19 }
20
21
22 type Profile struct {
23 ClientName string
24 Name string
25 Owner string
26 RedirectURIs []string
27 PrintBarcodeURI string
28 PrintBarcodeTypes []string
29 GrantTypes []string
30 ResponseTypes []string
31 ResponseModes []string
32 Scopes []string
33 Audience []string
34 Roles []string
35 Public bool
36 }
37
38 type Storage interface {
39 GetIAMClient(ctx context.Context, id string) (*Client, error)
40 GetClients(ctx context.Context, owner string) ([]*Client, error)
41 SaveClientProfile(ctx context.Context, clientID string, profile *Profile) (*Profile, error)
42 SaveClientCredentials(ctx context.Context, clientID string, creds *Credentials) (*Credentials, error)
43 DeleteClient(ctx context.Context, id string) error
44 }
45
46 func (c *Client) GetID() string {
47 return c.ID
48 }
49
50 func (c *Client) IsPublic() bool {
51 return c.Profile.Public
52 }
53
54 func (c *Client) GetAudience() fosite.Arguments {
55 return c.Profile.Audience
56 }
57
58 func (c *Client) GetRedirectURIs() []string {
59 return c.Profile.RedirectURIs
60 }
61
62 func (c *Client) GetPrintBarcodeURI() string {
63 return c.Profile.PrintBarcodeURI
64 }
65
66 func (c *Client) GetPrintBarcodeTypes() []string {
67 return c.Profile.PrintBarcodeTypes
68 }
69
70 func (c *Client) GetHashedSecret() []byte {
71 return []byte(c.Credentials.Secret)
72 }
73
74 func (c *Client) GetRotatedHashes() [][]byte {
75 return nil
76 }
77 func (c *Client) GetClientName() string {
78 return c.Profile.ClientName
79 }
80 func (c *Client) GetName() string {
81 return c.Profile.Name
82 }
83 func (c *Client) GetScopes() fosite.Arguments {
84 return c.Profile.Scopes
85 }
86
87 func (c *Client) GetGrantTypes() fosite.Arguments {
88 if len(c.Profile.GrantTypes) == 0 {
89 return fosite.Arguments{"authorization_code"}
90 }
91 return fosite.Arguments(c.Profile.GrantTypes)
92 }
93
94 func (c *Client) GetResponseTypes() fosite.Arguments {
95 if len(c.Profile.ResponseTypes) == 0 {
96 return fosite.Arguments{"code"}
97 }
98 return fosite.Arguments(c.Profile.ResponseTypes)
99 }
100
101 func (c *Client) GetResponseModes() []fosite.ResponseModeType {
102 if len(c.Profile.ResponseModes) == 0 {
103 return []fosite.ResponseModeType{""}
104 }
105
106 modes := make([]fosite.ResponseModeType, 0)
107 for _, mode := range c.Profile.ResponseModes {
108 switch mode {
109 case "form_post":
110 modes = append(modes, "form_post")
111 case "query":
112 modes = append(modes, "query")
113 case "fragment":
114 modes = append(modes, "fragment")
115 }
116 }
117
118 return modes
119 }
120
121 func (c *Client) GetRoles() []string {
122 if len(c.Profile.Roles) == 0 {
123 return []string{}
124 }
125
126 return c.Profile.Roles
127 }
128
View as plain text