blob: 54be5a437dcdeb3b46901336ced26e68b22f5966 [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 IIfd78c302013-06-25 16:35:32 -070050 return nil, nil
Samuel A. Falvo II5d0d74c2013-06-25 17:23:18 -070051
52 // if err != nil {
53 // return err
54 // }
55
56 // c.isAuthenticated = true
57 // c.token = id.access.Access.Token.Id
58 // c.expires = id.access.Access.Token.Expires
59 // c.tenantId = id.access.Access.Token.Tenant.Id
60 // c.tenantName = id.access.Access.Token.Tenant.Name
Samuel A. Falvo II1d3fa662013-06-25 15:29:32 -070061}