Skip to content

Commit

Permalink
request to get token
Browse files Browse the repository at this point in the history
  • Loading branch information
xer0x committed Jan 27, 2021
1 parent 6b02fc8 commit ddc7e80
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions internal/cli/apis.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package cli

import (
"fmt"
"github.com/auth0/auth0-cli/internal/ansi"
"github.com/auth0/auth0-cli/internal/prompt"
"github.com/spf13/cobra"
"gopkg.in/auth0.v5/management"
"io/ioutil"
"net/http"
"strings"
)

func apisCmd(cli *cli) *cobra.Command {
Expand Down Expand Up @@ -181,6 +185,35 @@ auth0 apis get-token --audience url
`,
RunE: func(cmd *cobra.Command, args []string) error {

cli.renderer.Infof("Requesting token...")

domain := "half-ogre-preview.auth0.com"

url := "https://" + domain + "/oauth/token"
client_id := "EMWsMvfZWFTBmZySFy8wcixosiiOGbK0"
client_secret := "4c3gyaIKKTj17T8lUhtJGUXSspMLuOYdLXQYLiRkmcr7Us06OmlksFNXit8IATah"

// This is audience
api_identifier := "https://cli.test.auth0.fake"

payload := strings.NewReader("grant_type=client_credentials&client_id=" + client_id + "&client_secret=" + client_secret + "&audience=" + api_identifier)

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("content-type", "application/x-www-form-urlencoded")

res, err := http.DefaultClient.Do(req)

if err != nil {
fmt.Println(err)
return nil
}

defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)

fmt.Println(res)
fmt.Println(string(body))
return nil
},
}
Expand Down

0 comments on commit ddc7e80

Please sign in to comment.