Example #1
0
// Mint a token for a given username and send it to the specified writer
func sendToken(w http.ResponseWriter, u string) {
	t := authn.GetToken(u)

	w.Header().Set("Content-Type", "application/json; charset=UTF-8")
	w.WriteHeader(http.StatusOK)

	if err := json.NewEncoder(w).Encode(authn.Token{Token: t}); err != nil {
		panic(err)
	}

}
Example #2
0
// Generate a token based on the key file and username
func main() {
	var keyfile string
	var username string

	flag.StringVar(&keyfile, "key", "key.base64", "A file containing the mint key")
	flag.StringVar(&username, "user", "", "Username to mint the token for")

	flag.Parse()

	authn.LoadMintKeyByName(keyfile)
	fmt.Print(authn.GetToken(username))

}
Example #3
0
		util.LoadConfigByName("test_config")
		router = NewRouter()
		recorder = httptest.NewRecorder()

		aFox = Fox{
			Name:    "Rein",
			Parents: []string{"2", "3"},
		}

		anotherFox = Fox{
			Name:    "NewName",
			Parents: []string{"4", "5"},
		}
		authn.InitValidator()
		authn.InitMint()
		token = authn.GetToken("testuser")
	})

	Describe("Adding foxes", func() {
		Context("Adding, reading and updating a fox", func() {
			// Simple adding of a fox
			It("Should return 201", func() {

				// Add the fox
				foxID := addFox(aFox, router)

				// See if we can find it
				_ = getFox(foxID, router)
			})
		})
	})
Example #4
0
	var newToken string
	var err error
	var user = "FantasticMrFox"
	var challange = "test"
	var provider = "pwd"

	BeforeEach(func() {
		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() {