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:
| Value | Description |
|---|---|
| Service‑Now URL | Base URL of the instance |
| Client ID | From a ServiceNow OAuth application registry entry |
| Redirect URL | Must match the redirect URL configured in ServiceNow |
| Authorization URL | OAuth authorization endpoint |
| Token URL | OAuth 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