Skip to content

Instantly share code, notes, and snippets.

@andymarch
Created April 3, 2020 12:31
Show Gist options
  • Save andymarch/a65528172f0be0b0b7833d92730182dc to your computer and use it in GitHub Desktop.
Save andymarch/a65528172f0be0b0b7833d92730182dc to your computer and use it in GitHub Desktop.
Create Okta App in Go
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://<<yourtenant>>/api/v1/apps"
method := "POST"
payload := strings.NewReader("{\n \"name\": \"oidc_client\",\n \"label\": \"Sample Client\",\n \"signOnMode\": \"OPENID_CONNECT\",\n \"credentials\": {\n \"oauthClient\": {\n \"token_endpoint_auth_method\": \"client_secret_post\"\n }\n },\n \"settings\": {\n \"oauthClient\": {\n \"redirect_uris\": [\n \"https://example.com/oauth2/callback\"\n ],\n \"response_types\": [\n \"code\"\n ],\n \"grant_types\": [\n \"authorization_code\"\n ],\n \"application_type\": \"web\"\n }\n }\n}")
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
}
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", "SSWS <<yourtoken>>")
req.Header.Add("Content-Type", "text/plain")
res, err := client.Do(req)
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}
package main
import (
"fmt"
"strings"
"net/http"
"io/ioutil"
)
func main() {
url := "https://<<yourtenant>>/oauth2/v1/clients"
method := "POST"
payload := strings.NewReader(" {\n \"client_name\": \"Web client\",\n \"redirect_uris\": [\n \"https://localhost:8080\"\n ],\n \"response_types\": [\n \"code\"\n ],\n \"grant_types\": [\n \"authorization_code\"\n ],\n \"token_endpoint_auth_method\": \"client_secret_basic\",\n \"application_type\": \"web\"\n }")
client := &http.Client {
}
req, err := http.NewRequest(method, url, payload)
if err != nil {
fmt.Println(err)
}
req.Header.Add("Accept", "application/json")
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", "SSWS <<yourtoken>>")
req.Header.Add("Content-Type", "text/plain")
res, err := client.Do(req)
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment