Getting error on Calling User UserApi from Okta sdk

Hi ,

i am trying to access UserApi using Okta sdk. i am getting error on calling userapi GetUserAsync method.

Kindly help me to access user using UserApi of okta sdk.

var oauthAppsApi = new UserApi(new Configuration
{
OktaDomain = “https://dev-xxxx.okta.com”,
AuthorizationMode = AuthorizationMode.BearerToken,
ClientId = “ABCClient”,
AccessToken= “XYZToken”
});

var user = await oauthAppsApi.GetUserAsync(“abcd@xyx.com”);
/// Exception Message : Okta.Sdk.Client.ApiException: 'Error calling GetUser: ’

Thanks for support

Hello,

Typically with the Management SDKs you would configure the app to use a private key in order to generate/sign a JWT which could be used to acquire an access_token from your Org.

It looks like you are providing an access_token directly.

  • What type of application is that access_token from
  • does the token have proper Okta API Scopes?
  • If the token is associated with a user, is that user in a admin role that gives enough permissions for the APIs being called
  • if the token is from a service app does the service app not only grant the correct Okta API scopes, but is the app associated with an admin role?

The following documentation demonstrates setting up OAuth for Okta from a service App. Once this is working the private key used can then be supplied to the SDK and it will acquire an access_token to use.

Thank You,