Skip to main content
Version: main

Authorization code (private)

The Authorization Code (private) flow works for applications that can securely store a client secret (for example, server-side services, desktop apps). A user authenticates interactively, and the SDK exchanges the authorization code for tokens.

Objective​

Configure and use the Authorization Code (private) 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
Client SecretFrom the same 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.NewPrivateAuthorizationCodeProvider(
"{clientID}",
"{clientSecret}",
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?