CreateBlogSupport
Log inSign up
Home
Webex Messaging
  • Overview
  • Guides
  • REST API Basics
  • API REFERENCE
  • All APIs
  • Changelog
  • SDK
  • AI Assistant for Developers
  • Widgets
  • Tutorials
  • Suite Sandbox
  • Beta Program
  • Webex Status API
  • XML API Deprecation

Webex Messaging

Authorization

The Webex Mobile Android SDK must be initialized and authorized to interact with the Webex platform. Your application should authenticate users through an OAuth grant flow for existing Cisco Webex users or a JSON web token (JWT) for guest users without a Cisco Webex account.

This article provides code examples explaining how to perform this authorization using either a built in Webview or an external browser.

anchorAuthorize Using a OAuth

anchor

OAuthWebViewAuthenticator utilizes a WebView for user authentication. Ensure the WebView is integrated into the view hierarchy before invoking the authorize method.

Initialize a Webex instance with OAuth authentication:

val clientId: String = "YOUR_CLIENT_ID"
val clientSecret: String = "YOUR_CLIENT_SECRET"
val redirectUri: String = "https://webexdemoapp.com"
val scope: String = "spark:all"
val email = "EMAIL_ID_OF_END_USER" // Email address for the end user.

val authenticator: OAuthWebViewAuthenticator = OAuthWebViewAuthenticator(clientId, clientSecret, scope, redirectUri, email)
val webex = Webex(application, authenticator)

webex.initialize(CompletionHandler { result ->
    if (result.error == null) {
        // Already authorized
    } else {
        authenticator.authorize(loginWebview, CompletionHandler { result ->
                if (result.error != null) {
                    // Handle the error
                }else{
                    // Authorization Successful
                }
            })
    }
})

anchorAuthorize Using a JSON Web Token(JWT)

anchor

JWTAuthenticator utilizes a JWT token for user authentication. Create a new Webex instance using JWT authentication

val token: String = "jwt_token"
val authenticator: JWTAuthenticator = JWTAuthenticator()
val webex = Webex(application, authenticator)
webex.initialize(CompletionHandler { result ->
    if (result.error == null) {
        // Already authorised
    } else {
        authenticator.authorize(token, CompletionHandler { result ->
                if (result.error != null) {
                    // Handle the error
                }else{
                    // Authorization Successful
                    webex.spaces.setOnInitialSpacesSyncCompletedListener( CompletionHandler { result->
                        if(result.isSuccessful){
                            // Initial Sync successful
                        } 
                    }
                }
            })
    }
})

anchorAuthorize Using a Acess Token

anchor

TokenAuthenticator utilizes a access token for user authentication. Create a new Webex instance using access token authentication

val token: String = "<your-access-token>"
 val expiryInSeconds = 60      // Expiry time in seconds
 val authenticator: TokenAuthenticator = TokenAuthenticator()
 val webex = Webex(application, authenticator)
 webex.initialize(CompletionHandler { result ->
     if (result.error == null) {
         // Already authorised
     } else {
         authenticator.authorize(token, expiryInSeconds, CompletionHandler { result ->
                 if (result.error != null) {
                     // Handle the error
                 }else{
                     // Authorization successful
                     webex.spaces.setOnInitialSpacesSyncCompletedListener( CompletionHandler { result->
                         if(result.isSuccessful){
                             // Initial Sync successful
                         } 
                     }
                 }
             })
     }
 })

anchorAuthorize Using an External Browser

anchor

As an alternative, OAuthAuthenticator can be used, which eliminates the need for a WebView. Developers have the flexibility to use any browser or WebView for authentication and then provide the authorization code to the SDK through OAuthAuthenticator:

val clientId: String = "YOUR_CLIENT_ID"
val clientSecret: String = "YOUR_CLIENT_SECRET"
val redirectUri: String = "https://webexdemoapp.com"
val scope: String = "spark:all"
val email = "EMAIL_ID_OF_END_USER" // Email address for the end user.

val authenticator: OAuthAuthenticator = OAuthAuthenticator(clientId, clientSecret, scope, redirectUri, email)
val webex = Webex(application, authenticator)

webex.initialize(CompletionHandler { result ->
    if (result.error == null) {
        // Already authorized
    } else {
        authenticator.getAuthorizationUrl(CompletionHandler { result ->
            if (result.error != null) {
                // Handle the error
            }else{
                // result.data
                // Use this URL to launch in either Webview or a web browser and then pass the authCode to the Authenticator's authorize method.
            }
        })
    }
})

authenticator.authorize(authCode, CompletionHandler { result ->
    if (result.error != null) {
        // Handle the error
    }else{
        // Authorization successful
    }
})
In This Article
  • Authorize Using a OAuth
  • Authorize Using a JSON Web Token(JWT)
  • Authorize Using a Acess Token
  • Authorize Using an External Browser

Connect

Support

Developer Community

Developer Events

Contact Sales

Handy Links

Webex Ambassadors

Webex App Hub

Resources

Open Source Bot Starter Kits

Download Webex

DevNet Learning Labs

Terms of Service

Privacy Policy

Cookie Policy

Trademarks

© 2025 Cisco and/or its affiliates. All rights reserved.