Example #1
0
func (c *LoginController) getAuthToken(w http.ResponseWriter, req *http.Request) error {
	sess, err := provider.BeginAuth(gothic.SetState(req))
	if err != nil {
		return err
	}

	url, err := sess.GetAuthURL()
	if err != nil {
		return err
	}
	c.SetSession("openl_login_session", sess.Marshal())
	if err != nil {
		w.WriteHeader(http.StatusBadRequest)
		return nil
	}

	http.Redirect(w, req, url, http.StatusTemporaryRedirect)
	return nil
}
Example #2
0
		BeforeEach(func() {
			ws.Auth.OAuth = OAuthConfig{
				Provider: "faux",
				Sessions: SessionsConfig{
					Type: "mock",
				},
			}
			req, err = http.NewRequest("GET", "/", nil)
			if err != nil {
				panic(err)
			}
			gothic.Store = &FakeSessionStore{}
			gothic.Store.Get(req, gothic.SessionName)
		})
		It("sets up gothic.GetProviderName to return the configured provider", func() {
			Expect(ws.Setup()).Should(Succeed())
			Expect(gothic.GetProviderName(req)).Should(Equal("faux"))
		})
		It("sets up gothic.SetState to return a unique state value every time", func() {

			Expect(ws.Setup()).Should(Succeed())
			firstState := gothic.SetState(req)
			Expect(firstState).Should(Equal(gothic.Store.(*FakeSessionStore).Session.Values["state"]))
			secondState := gothic.SetState(req)
			Expect(secondState).ShouldNot(Equal(firstState))
			Expect(secondState).Should(Equal(gothic.Store.(*FakeSessionStore).Session.Values["state"]))

		})
	})
})