Esempio n. 1
0
func (z ZonedUAAClient) UsersGUIDsByScope(token string, scope string) ([]string, error) {
	uaaHost, err := z.tokenHost(token)
	if err != nil {
		return nil, err
	}

	uaaSSOGolangClient := uaaSSOGolang.NewUAA("", uaaHost, z.clientID, z.clientSecret, "")
	uaaSSOGolangClient.VerifySSL = z.verifySSL

	return uaaSSOGolangClient.UsersGUIDsByScope(scope)
}
Esempio n. 2
0
func (z ZonedUAAClient) AllUsers(token string) ([]User, error) {
	uaaHost, err := z.tokenHost(token)
	if err != nil {
		return nil, err
	}

	uaaSSOGolangClient := uaaSSOGolang.NewUAA("", uaaHost, z.clientID, z.clientSecret, "")
	uaaSSOGolangClient.VerifySSL = z.verifySSL
	users, err := uaaSSOGolangClient.AllUsers()

	var myUsers []User
	for _, user := range users {
		myUsers = append(myUsers, newUserFromSSOGolangUser(user))
	}

	return myUsers, err
}
Esempio n. 3
0
func (z ZonedUAAClient) UsersEmailsByIDs(token string, ids ...string) ([]User, error) {
	uaaHost, err := z.tokenHost(token)
	if err != nil {
		return nil, err
	}

	uaaClient := uaaSSOGolang.NewUAA("", uaaHost, z.clientID, z.clientSecret, "")
	uaaClient.VerifySSL = z.verifySSL
	uaaClient.SetToken(token)

	var myUsers []User
	users, err := uaaClient.UsersEmailsByIDs(ids...)
	if err != nil {
		return myUsers, err
	}

	for _, user := range users {
		myUsers = append(myUsers, newUserFromSSOGolangUser(user))
	}

	return myUsers, nil
}
Esempio n. 4
0
func GetUAAClientFor(clientID string) uaa.UAA {
	return uaa.NewUAA("", Servers.UAA.ServerURL, clientID, "secret", "")
}
				}

				responseObj["resources"] = usersList

				response, err := json.Marshal(responseObj)
				if err != nil {
					panic(err)
				}

				w.WriteHeader(http.StatusOK)
				w.Write([]byte(response))
			} else {
				w.WriteHeader(http.StatusNotFound)
			}
		}))
		auth = uaa.NewUAA("http://uaa.example.com", fakeUAAServer.URL, "the-client-id", "the-client-secret", "my-special-token")
	})

	It("returns slice of Users from UAA", func() {
		users, err := uaa.UsersEmailsByIDs(auth, "87dfc5b4-daf9-49fd-9aa8-bb1e21d28929", "baf908c9-3248-451f-ab3c-103d921cd61e")
		if err != nil {
			panic(err)
		}

		user1 := uaa.User{
			Emails: []string{"*****@*****.**"},
			ID:     "87dfc5b4-daf9-49fd-9aa8-bb1e21d28929",
		}

		user2 := uaa.User{
			Emails: []string{"*****@*****.**"},
						return
					}

					response := `{
                            "access_token": "client-access-token",
                            "refresh_token": "refresh-token",
                            "token_type": "bearer"
                        }`

					w.WriteHeader(http.StatusOK)
					w.Write([]byte(response))
				} else {
					w.WriteHeader(http.StatusNotFound)
				}
			}))
			auth = uaa.NewUAA("http://login.example.com", fakeUAAServer.URL, "the-client-id", "the-client-secret", "")
		})

		AfterEach(func() {
			fakeUAAServer.Close()
		})

		It("returns the client auth token", func() {
			token, err := uaa.GetClientToken(auth)
			Expect(err).To(BeNil())
			Expect(token.Access).To(Equal("client-access-token"))
		})
	})

	Context("when UAA is not responding normally", func() {
		BeforeEach(func() {
						return
					}

					response := `{
                            "access_token": "client-access-token",
                            "refresh_token": "refresh-token",
                            "token_type": "bearer"
                        }`

					w.WriteHeader(http.StatusOK)
					w.Write([]byte(response))
				} else {
					w.WriteHeader(http.StatusNotFound)
				}
			}))
			auth = uaa.NewUAA("", fakeUAAServer.URL, "the-client-id", "the-client-secret", "")
		})

		It("returns the public key that UAA tokens can be validated with", func() {
			key, err := uaa.GetTokenKey(auth)
			if err != nil {
				panic(err)
			}

			Expect(key).To(Equal("THIS-IS-THE-PUBLIC-KEY"))
		})
	})

	Context("when UAA is not responding normally", func() {
		BeforeEach(func() {
			fakeUAAServer = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
Esempio n. 8
0
package uaa_test

import (
	"reflect"

	"github.com/pivotal-cf/uaa-sso-golang/uaa"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("UAA", func() {
	var auth uaa.UAA

	BeforeEach(func() {
		auth = uaa.NewUAA("http://login.example.com", "http://uaa.example.com", "the-client-id", "the-client-secret", "")
	})

	Describe("NewUAA", func() {
		It("defaults VerifySSL to true", func() {
			Expect(auth.VerifySSL).To(BeTrue())
		})
	})

	Describe("AuthorizeURL", func() {
		It("returns the URL for the /oauth/authorize endpoint", func() {
			Expect(auth.AuthorizeURL()).To(Equal("http://login.example.com/oauth/authorize"))
		})
	})

	Describe("LoginURL", func() {
Esempio n. 9
0
func (z ZonedUAAClient) GetTokenKey(uaaHost string) (string, error) {
	uaaSSOGolangClient := uaaSSOGolang.NewUAA("", uaaHost, z.clientID, z.clientSecret, "")
	uaaSSOGolangClient.VerifySSL = z.verifySSL
	return uaaSSOGolangClient.GetTokenKey()
}