blob: 2320da7914a04a229eb33371c3ece7b55b1b40ff [file] [log] [blame]
Samuel A. Falvo II1d3fa662013-06-25 15:29:32 -07001package gophercloud
2
Samuel A. Falvo II5d0d74c2013-06-25 17:23:18 -07003import (
4 "github.com/racker/perigee"
5)
6
Samuel A. Falvo II1d3fa662013-06-25 15:29:32 -07007type AuthOptions struct {
8 Username, Password, TenantId string
9}
10
Samuel A. Falvo II5d0d74c2013-06-25 17:23:18 -070011type AuthContainer struct {
12 Auth Auth `json:"auth"`
13}
14
15type Auth struct {
16 PasswordCredentials PasswordCredentials `json:"passwordCredentials"`
17 TenantId string `json:"tenantId,omitempty"`
18}
19
20type PasswordCredentials struct {
21 Username string `json:"username"`
22 Password string `json:"password"`
23}
24
25type ProviderAccess interface {
26 // ...
27}
28
29func (c *Context) Authenticate(provider string, options AuthOptions) (ProviderAccess, error) {
30 p, err := c.ProviderByName(provider)
Samuel A. Falvo IIfd78c302013-06-25 16:35:32 -070031 if err != nil {
32 return nil, err
33 }
Samuel A. Falvo IIfd78c302013-06-25 16:35:32 -070034 if (options.Username == "") || (options.Password == "") {
35 return nil, ErrCredentials
36 }
Samuel A. Falvo II5d0d74c2013-06-25 17:23:18 -070037
38 err = perigee.Post(p.AuthEndpoint, perigee.Options{
39 CustomClient: c.httpClient,
40 ReqBody: &AuthContainer{
41 Auth: Auth{
42 PasswordCredentials: PasswordCredentials{
43 Username: options.Username,
44 Password: options.Password,
45 },
46 TenantId: options.TenantId,
47 },
48 },
49 })
Samuel A. Falvo II978fed82013-06-25 17:59:19 -070050 return nil, err
Samuel A. Falvo II1d3fa662013-06-25 15:29:32 -070051}