govisual-studio-codeokta

Okta Go Api GetApplication using VSCode


I am attempting to instantiate a client, based on the sample https://github.com/okta/okta-sdk-golang?tab=readme-ov-file#get-an-application. No matter what I do I always get:

a 401 Unauthorized Error.

The response is very limited. Anyone know what I am doing wrong? I get the token and use the application name of thisIsMyApplication.

package main

import (
    "context"
    "encoding/json"
    "fmt"
    "net/http"

    "github.com/okta/okta-sdk-golang/v5/okta"
)
    func main() {
            token := "bearerTokenFromOktaServer"
        
            // okta
            config, err := okta.NewConfiguration(
                okta.WithOrgUrl("https:oktaServer/oauth2/default/v1/token"),
                okta.WithToken(token),
            )
            if err != nil {
                fmt.Printf("Error: %v\n", err)
            }
            client := okta.NewAPIClient(config)
        
            application, resp, err := client.ApplicationAPI.GetApplication(client.GetConfig().Context, "thisIsMyApplication").Execute()
            if err != nil {
                fmt.Printf("Error getting application: %v\n", err)
            }
            fmt.Printf("Application: %+v\n Response: %+v\n\n", application, resp)
    }

The Response:

DAP server listening at: 127.0.0.1:56207
Type 'dlv help' for list of commands.
Error getting application: 401 Unauthorized
Application: <nil>
 Response: &{Response:0xc0001dc630 cli:0xc000202108 pg:0xc00011a000}

Solution

  • Marking this as closed as using a different IDE provided a valid response object for me to dig deeper into. Thanks for your help everyone!