Skip to Content
DocumentationAndroid SDK

Using Veslo Auth Android SDK with JitPack

This guide explains how to integrate the Veslo Auth SDK into your Android application using JitPack.

1. Installation

Add JitPack Repository

Add the JitPack repository to your root settings.gradle.kts (or project-level build.gradle.kts):

dependencyResolutionManagement {
    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
    repositories {
        google()
        mavenCentral()
        maven { url = uri("https://jitpack.io") } // <-- Add this line
    }
}

Add Dependency

In your module’s build.gradle.kts (usually app/build.gradle.kts), add the dependency:

dependencies {
    implementation("com.github.BranislavPop:veslo-auth-sdk-android:1.0.0")
}

2. Configuration

Manifest Placeholders

To handle the OAuth redirect, you need to configure the appAuthRedirectScheme placeholder. This should match the scheme of your redirect URI (e.g., if redirect URI is com.myapp:/callback, the scheme is com.myapp).

In app/build.gradle.kts:

android {
    defaultConfig {
        // ...
        manifestPlaceholders["appAuthRedirectScheme"] = "com.yourapp" 
    }
}

Note: You do NOT need to manually declare RedirectUriReceiverActivity in your AndroidManifest.xml. The SDK includes the necessary configuration which will be merged into your app automatically using the placeholder.

3. Usage

Initialize the SDK

Initialize VesloAuth in your Application class or main Activity’s onCreate:

val config = AuthConfig.Builder()
    .clientId("your-client-id")
    .redirectUri("com.yourapp:/callback") // Scheme must match manifestPlaceholder
    .discoveryUri("https://id.veslo.io/.well-known/openid-configuration")
    .scopes(listOf("openid", "profile", "email", "offline_access"))
    .enableLogging(BuildConfig.DEBUG) // Optional: Enable logs for debugging
    .build()
 
VesloAuth.initialize(this, config)

Sign In

Trigger the sign-in flow (e.g., on button click):

signInButton.setOnClickListener {
    VesloAuth.signIn(this)
}

Handle the Redirect

When the user completes login, the browser will redirect back to your app. You need to capture this in your Activity, typically in onNewIntent (if launchMode="singleTop") or onCreate.

override fun onNewIntent(intent: Intent?) {
    super.onNewIntent(intent)
    intent?.let {
        // Handle the auth response
        lifecycleScope.launch {
            VesloAuth.handleAuthResponse(it)
                .onSuccess {
                    // Login successful
                }
                .onFailure { error ->
                    // Login failed
                }
        }
    }
}

Get User Info & Tokens

Once authenticated, you can retrieve the access token or user profile:

// Get User Info (caches automatically)
VesloAuth.getUserInfo()
    .onSuccess { user ->
        println("User: ${user.name}, ${user.email}")
    }
 
// Get Access Token (refreshes automatically if needed)
VesloAuth.getAccessToken()
    .onSuccess { token ->
        // Use token in API headers
    }

Observe Auth State

You can observe the authentication state to update your UI (e.g., show/hide login button):

lifecycleScope.launch {
    VesloAuth.state.collect { state ->
        when (state) {
            is VesloAuthState.Idle -> showLogin()
            is VesloAuthState.Authenticated -> showHome()
            is VesloAuthState.Error -> showError(state.exception)
            else -> {}
        }
    }
}

4. ProGuard / R8

The SDK includes consumer rules that are automatically applied. No extra configuration is needed.

Last updated on