Functional GoLang Oath2 Example

Apologies, I am not a top level developer and reading all the github docs and SDK’s is making me cross-eyed…

Could anyone provide a functional example of using Oath2 in a GoLang app? I have the basics, but I am quite unsure about the layout and where to put things…

So far I have this…

package main

import (
	"context"
	"fmt"

	"github.com/okta/okta-sdk-golang/v2/okta"
)

func main() {
	ctx := context.TODO()
	ctx, client, err := okta.NewClient(ctx,
		okta.WithOrgUrl("https://mycompany.okta.com"),
		okta.WithAuthorizationMode("PrivateKey"),
		okta.WithClientId("{myClientId}"),
		okta.WithScopes([]string{"'okta.groups.read','okta.users.read','okta.groups.manage'"}),
		okta.WithPrivateKey("{private_key}"),
		okta.WithPrivateKeyId("{private key id}"), //needed if Okta service application has more then a single JWK registered
	)

	if err != nil {
		fmt.Printf("Error: %v\n", err)
	}

	fmt.Printf("Context: %+v\n Client: %+v\n", ctx, client)

	user, resp, err := client.User.GetUser(ctx, "{UserId|Username|Email}")
	if err != nil {
		fmt.Printf("Error Getting User: %v\n", err)
	}
	fmt.Printf("User: %+v\n Response: %+v\n\n", user, resp)
}

Adding on to this… There is Postman examples, but they are all using an API key. Our company has decided that we can only use Oath.

Hey there, thank you for writing to Okta Dev Forum. My name is Akash, from Okta.

My I know what exactly you are trying to achieve? Please provide me with your use case in detail, which will help understand them better and get you the right resources.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.