示例#1
0
文件: Handlers.go 项目: livenson/fox
// Login returns a token
func Login(w http.ResponseWriter, r *http.Request) {
	u := r.FormValue("username")
	c := r.FormValue("challenge")
	p := r.FormValue("provider")

	// We need all three
	if u == "" || c == "" || p == "" {
		w.WriteHeader(http.StatusBadRequest)
		return
	}

	// If the credentials check out
	if authn.Authenticate(u, c, p) {
		sendToken(w, u)
	} else {
		// The credentials did not check out
		w.WriteHeader(http.StatusForbidden)
	}

}
示例#2
0
		util.LoadConfigByName("test_config")
		authn.InitMint()
		authn.InitValidator()
	})

	Describe("Token roundtrip", func() {
		Context("Freshly minted token", func() {
			It("Fresh token should be valid", func() {
				user, err := authn.Validate(authn.GetToken(user))
				Expect(err).To(BeNil())
				Expect(user).To(Equal(user))
			})
		})
		Context("Authenticating the user", func() {
			It("should return true, given valid username, challange and provider", func() {
				bool := authn.Authenticate(user, challange, provider)
				Expect(bool).To(BeTrue())
			})
		})
	})

	Describe("Reissuing a token", func() {
		Context("Username is preserved", func() {
			It("should return the username that was given to the old token", func() {
				oldToken = authn.GetToken(user)
				newToken, err = authn.ReissueToken(oldToken)
				Expect(err).To(BeNil())

				u, err := authn.Validate(newToken)
				Expect(err).To(BeNil())
				Expect(u).To(Equal(user))