auth
25:9fc5fd8196b4 Browse Files
Rough out client. Remove our old client implementation, and start exploring a new ClientStore interface for storing and retrieving Client data. Keep track of a website for clients.
1.1 --- a/client.go Mon Sep 01 09:14:48 2014 -0400 1.2 +++ b/client.go Mon Sep 01 09:15:56 2014 -0400 1.3 @@ -4,7 +4,9 @@ 1.4 "secondbit.org/uuid" 1.5 ) 1.6 1.7 -// Client information 1.8 +// Client represents a client that grants access 1.9 +// to the auth server, exchanging grants for tokens, 1.10 +// and tokens for access. 1.11 type Client struct { 1.12 ID uuid.ID 1.13 Secret string 1.14 @@ -12,40 +14,15 @@ 1.15 OwnerID uuid.ID 1.16 Name string 1.17 Logo string 1.18 + Website string 1.19 } 1.20 1.21 -func GetClient(id uuid.ID, ctx Context) (Client, error) { 1.22 - return ctx.Clients.GetClient(id) 1.23 +// ClientStore abstracts the storage interface for 1.24 +// storing and retrieving Clients. 1.25 +type ClientStore interface { 1.26 + GetClient(id uuid.ID) (Client, error) 1.27 + SaveClient(client Client) error 1.28 + UpdateClient(id uuid.ID, secret, redirectURI *string, ownerID uuid.ID, name, logo, website *string) error 1.29 + DeleteClient(id uuid.ID) error 1.30 + ListClientsByOwner(ownerID uuid.ID, page, num int) ([]Client, error) 1.31 } 1.32 - 1.33 -func createClient(name, logo, redirectURI string, owner uuid.ID, ctx Context) (Client, error) { 1.34 - return ctx.Clients.CreateClient(name, logo, redirectURI, owner) 1.35 -} 1.36 - 1.37 -func updateClient(client *Client, name, logo, redirectURI *string, ctx Context) error { 1.38 - if client == nil { 1.39 - return NilClientError 1.40 - } 1.41 - err := ctx.Clients.UpdateClient(client.ID, name, logo, redirectURI) 1.42 - if err != nil { 1.43 - return err 1.44 - } 1.45 - if name != nil { 1.46 - client.Name = *name 1.47 - } 1.48 - if logo != nil { 1.49 - client.Logo = *logo 1.50 - } 1.51 - if redirectURI != nil { 1.52 - client.RedirectURI = *redirectURI 1.53 - } 1.54 - return nil 1.55 -} 1.56 - 1.57 -func removeClient(id uuid.ID, ctx Context) error { 1.58 - return ctx.Clients.RemoveClient(id) 1.59 -} 1.60 - 1.61 -func listClients(id uuid.ID, page, num int, ctx Context) ([]Client, error) { 1.62 - return ctx.Clients.ListClients(id, page, num) 1.63 -}