Package 

Interface StreamTokenProvider


  • 
    public interface StreamTokenProvider
    
                        

    Supplies authentication tokens (JWTs) for a given user.

    Implementations usually call your backend to mint or fetch a signed, short-lived JWT for the provided user ID. Never embed server secrets or mint tokens on-device.

    • Must return a valid, signed JWT for the requested userId.

    • May be invoked multiple times (e.g., initial connect, refresh); implement caching if appropriate.

    • This is a suspend function; perform network/IO work without blocking and respect cancellation.

    • Signal failures by throwing an exception (don’t return empty/placeholder tokens).

    class MyTokenProvider(
        private val authApi: AuthApi
    ) : StreamTokenProvider {
        override suspend fun loadToken(userId: String): StreamToken {
            // Network call to your service; may throw on failure
            val response = authApi.issueToken(userId)
            val streamToken = StreamToken.from(response.token)
            return streamToken
        }
    }
    • Token creation/rotation must happen on your server.

    • Prefer short expirations and refresh on demand.

    • Method Summary

      Modifier and Type Method Description
      abstract StreamToken loadToken(StreamUserId userId) Returns a JWT that authenticates the given userId.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • loadToken

         abstract StreamToken loadToken(StreamUserId userId)

        Returns a JWT that authenticates the given userId.

        Called by the SDK when establishing a connection and whenever a token refresh is needed. Implementations may perform network requests and should be cancellable.

        Note: do not return a placeholder token or an empty string, throw an exception instead.

        Parameters:
        userId - The user identifier the token should be issued for.