package client import ( "context" "github.com/ory/fosite" ) // Client represents an OAuth2 client digestible by fosite type Client struct { ID string Profile *Profile Credentials *Credentials } // Credentials is the model representation of a persisted client credentials type Credentials struct { Secret string } // Profile is the model representation of a persisted client profile type Profile struct { ClientName string Name string Owner string RedirectURIs []string PrintBarcodeURI string PrintBarcodeTypes []string GrantTypes []string ResponseTypes []string ResponseModes []string Scopes []string Audience []string Roles []string Public bool } type Storage interface { GetIAMClient(ctx context.Context, id string) (*Client, error) GetClients(ctx context.Context, owner string) ([]*Client, error) SaveClientProfile(ctx context.Context, clientID string, profile *Profile) (*Profile, error) SaveClientCredentials(ctx context.Context, clientID string, creds *Credentials) (*Credentials, error) DeleteClient(ctx context.Context, id string) error } func (c *Client) GetID() string { return c.ID } func (c *Client) IsPublic() bool { return c.Profile.Public } func (c *Client) GetAudience() fosite.Arguments { return c.Profile.Audience } func (c *Client) GetRedirectURIs() []string { return c.Profile.RedirectURIs } func (c *Client) GetPrintBarcodeURI() string { return c.Profile.PrintBarcodeURI } func (c *Client) GetPrintBarcodeTypes() []string { return c.Profile.PrintBarcodeTypes } func (c *Client) GetHashedSecret() []byte { return []byte(c.Credentials.Secret) } func (c *Client) GetRotatedHashes() [][]byte { return nil } func (c *Client) GetClientName() string { return c.Profile.ClientName } func (c *Client) GetName() string { return c.Profile.Name } func (c *Client) GetScopes() fosite.Arguments { return c.Profile.Scopes } func (c *Client) GetGrantTypes() fosite.Arguments { if len(c.Profile.GrantTypes) == 0 { return fosite.Arguments{"authorization_code"} } return fosite.Arguments(c.Profile.GrantTypes) } func (c *Client) GetResponseTypes() fosite.Arguments { if len(c.Profile.ResponseTypes) == 0 { return fosite.Arguments{"code"} } return fosite.Arguments(c.Profile.ResponseTypes) } func (c *Client) GetResponseModes() []fosite.ResponseModeType { if len(c.Profile.ResponseModes) == 0 { return []fosite.ResponseModeType{""} } modes := make([]fosite.ResponseModeType, 0) for _, mode := range c.Profile.ResponseModes { switch mode { case "form_post": modes = append(modes, "form_post") case "query": modes = append(modes, "query") case "fragment": modes = append(modes, "fragment") } } return modes } func (c *Client) GetRoles() []string { if len(c.Profile.Roles) == 0 { return []string{} } return c.Profile.Roles }