コード例 #1
0
ファイル: Handlers.go プロジェクト: e-gov/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
ファイル: authn_test.go プロジェクト: e-gov/fox
		util.LoadConfigByPathWOExtension("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, challenge and provider", func() {
				booln := authn.Authenticate(user, challenge, provider)
				Expect(booln).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() {
				fmt.Println("GetToken " + user)
				oldToken = authn.GetToken(user)
				fmt.Println("OldToken " + oldToken)
				newToken, err = authn.ReissueToken(oldToken)
				fmt.Println("Reissued " + newToken)
				Expect(err).To(BeNil())