AuthorizationToken class - Android

  • リリースバージョン: Australia
  • 更新日 2026年03月12日
  • 所要時間:2分
  • The AuthorizationToken class provides the authorization token provided by the host application. Used by the NowSDK to authorize access to a specified ServiceNow instance for the currently logged in user.

    表 : 1. Properties
    Name Type Description
    token String Value of the authorization token.
    type String Type of authorization token.
    Valid values (case-sensitive):
    • JWT
    • OAuthAccess
    • OAuthRefresh

    AuthorizatonToken - AuthorizationToken(type: AuthorizationTokenType, token: String)

    Returns the authorization token provided by the host application.

    表 : 2. Parameters
    Name Type Description
    type String Type of authorization token.
    Valid values (case-sensitive):
    • JWT
    • OAuthAccess
    • OAuthRefresh
    token String Value of the authorization token.
    表 : 3. Returns
    Type Description
    None

    class SDKManager @Inject constructor(
      private val settings: Provider<NowSDKSettings>,
      private val jwtService: JWTService
    ) : NowSDKAuthorizationProviding,
      DevicePermissionDelegate {
    
      override fun requestAuthorization(
        instanceURL: URL,
        callback: Consumer<List<AuthorizationToken>?>
      ) {
          GlobalScope.launch(Dispatchers.IO) {
            try {
              val token = jwtService.getJWT(settings.get().user, settings.get().clientId).token
              callback.accept(
                listOf(
                  AuthorizationToken(
                    AuthorizationTokenType.JWT,
                    token
                  )
                )
              )
            } catch (ex : Exception) {
               Log.e("JWT", "Failed to get jwt", ex)
               return@launch callback.accept(null)
            }
          }
        }