Exemplo n.º 1
0
func (c *Client) Create(ctx *cli.Context) {
	seq, err := sequence.RuneSequence(10, []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"))
	if err != nil {
		log.Fatalf("err")
	}

	client := &osin.DefaultClient{
		Id:          uuid.New(),
		Secret:      string(seq),
		RedirectUri: "",
		UserData:    "",
	}

	c.Ctx.Start()
	if err := c.Ctx.Osins.CreateClient(client); err != nil {
		log.Fatalf("%s", err)
	}

	fmt.Printf(`Created client "%s" with secret "%s".`+"\n", client.Id, client.Secret)

	if ctx.Bool("as-superuser") {
		if err := c.Ctx.Policies.Create(superUserPolicy(client.Id)); err != nil {
			log.Fatalf("%s", err)
		}
		fmt.Printf(`Granted superuser privileges to client "%s".`+"\n", client.Id)
	}
}
Exemplo n.º 2
0
func (c *User) Create(ctx *cli.Context) {
	email := ctx.Args().First()
	if email == "" {
		log.Fatalf("Please provide an email address.")
	}
	password := ctx.String("password")
	if password == "" {
		password = getPassword()
	}

	c.Ctx.Start()
	user, err := c.Ctx.Accounts.Create(uuid.New(), email, password, "{}")
	if err != nil {
		log.Fatalf("%s", err)
	}

	fmt.Printf(`Created user as "%s".`+"\n", user.GetID())

	if ctx.Bool("as-superuser") {
		if err := c.Ctx.Policies.Create(superUserPolicy(user.GetID())); err != nil {
			log.Fatalf("%s", err)
		}
		fmt.Printf(`Granted superuser privileges to user "%s".`+"\n", user.GetID())
	}
}