Skip to main content
Version: main

Authorization code (public)

The Authorization Code (public) flow works for applications that authenticate users interactively but can't securely store a client secret (for example, SPAs, mobile apps, CLI tools).

Objective​

Configure and use the Authorization Code (public) OAuth flow with the Service‑Now SDK using values provided by your ServiceNow administrator.

Required values​

Your administrator must provide:

ValueDescription
Service‑Now URLBase URL of the instance
Client IDFrom a ServiceNow OAuth application registry entry
Redirect URLMust match the redirect URL configured in ServiceNow
Authorization URLOAuth authorization endpoint
Token URLOAuth token endpoint

SDK flow​

Initialize the SDK​

cred, err := credentials.NewPublicAuthorizationCodeProvider(
"{clientID}",
credentials.WithInstance("{instance}"),
)
if err != nil {
log.Fatal(err)
}

client, err := servicenowsdkgo.NewServiceNowServiceClient(
servicenowsdkgo.WithAuthenticationProvider(cred),
servicenowsdkgo.WithInstance("{instance}"),
)
if err != nil {
log.Fatal(err)
}

// Client is now authenticated and ready to use
_ = client
Was this page helpful?