Beispiel #1
0
func CreateClient() {
	reader := bufio.NewReader(os.Stdin)
	fmt.Print("Client name: ")
	clientName, _ := reader.ReadString('\n')
	clientName = strings.Trim(clientName, "\n")
	fmt.Print("Client description: ")
	clientDescription, _ := reader.ReadString('\n')
	clientDescription = strings.Trim(clientDescription, "\n")
	fmt.Print("Client scope: ")
	clientScope, _ := reader.ReadString('\n')
	clientScope = strings.Trim(clientScope, "\n")
	fmt.Print("Client canonical URI: ")
	canonicalURI, _ := reader.ReadString('\n')
	canonicalURI = strings.Trim(canonicalURI, "\n")
	fmt.Print("Client URI redirect: ")
	redirectURI, _ := reader.ReadString('\n')
	redirectURI = strings.Trim(redirectURI, "\n")

	clientSecret := models.GenerateRandomString(64)
	client := services.CreateNewClient(clientName,
		clientDescription,
		clientSecret,
		clientScope,
		canonicalURI,
		redirectURI)
	if client.ID == 0 {
		fmt.Println("There's a error and the client was not created")
	} else {
		fmt.Println("A new client application was created")
		fmt.Println("Client key: ", client.Key)
		fmt.Println("Client secret: ", clientSecret)
	}
}
Beispiel #2
0
func FindOrCreateClient(name string) models.Client {
	var client models.Client

	dataStoreSession := datastore.GetDataStoreConnection()
	dataStoreSession.Where("name = ?", name).First(&client)
	if dataStoreSession.NewRecord(client) {
		client = models.Client{
			Name:         name,
			Secret:       models.GenerateRandomString(64),
			CanonicalURI: "localhost",
			RedirectURI:  "/",
			Scopes:       models.PublicScope,
			Type:         models.PublicClient,
		}
		dataStoreSession.Create(&client)
	}
	return client
}