Skip to content

[Bug] OIDC ACTION_CREATE omits consent for offline_access, causing missing refresh token — fix verified on Android device #243

Closed

Description

@v1rusnl

Fix Proposal

#244

Summary

OpenCloud Android 1.2.5 fails to add an account when using an OpenID Connect provider that requires explicit consent before granting the offline_access scope and issuing a refresh token.

The issue occurs during initial account creation (ACTION_CREATE).

Although the Android application correctly requests offline_access, its initial authorization request unconditionally contains:

prompt=login

When using VoidAuth v1.16.0 as the OIDC provider, this produces a successful authorization code exchange and valid access/ID tokens, but no refresh token.

The Android application subsequently fails with:

invalid refresh token

After an extensive investigation, I identified the relevant code path, reproduced the behavior with independent Authorization Code + PKCE tests, implemented a minimal scope-aware fix, built a signed QA/debug APK, ran three successful Robolectric tests, and verified the modified application on a physical Android device.

The modified Android application successfully completed OIDC authentication and logged into the existing OpenCloud account.

The functional change is:

- prompt=login
+ prompt=login consent

This change is applied only when creating an account and requesting offline_access. The existing behavior is preserved when offline_access is not requested and for other login actions.

Confirmed results

  • Unmodified Android application: Login fails with invalid refresh token.
  • Independent OIDC test with prompt=login: HTTP 200, but no refresh token.
  • Independent OIDC test with prompt=consent: HTTP 200, refresh token present.
  • Independent OIDC test with prompt=login consent: HTTP 200, refresh token present.
  • Modified Android application: Successfully logged in on a physical Android device.
  • Automated tests: 3 passed, 0 failed, 0 errors, 0 skipped.
  • QA/debug APK: Successfully built, signed, and verified.

This report contains the complete troubleshooting history, root-cause analysis, proposed patch, test results, build information, and real-device validation.


Environment

Component Version / Configuration
OpenCloud server 8.1.0
Official OpenCloud Android app 1.2.5
Modified Android test application 1.2.5 (11), QA/debug build
OIDC provider VoidAuth v1.16.0
VoidAuth Docker image tag latest
OpenCloud Desktop 4.0, working
OpenCloud Web Working
Android OIDC client ID OpenCloudAndroid
Android redirect URI oc://android.opencloud.eu
OIDC flow Authorization Code
PKCE S256
Requested scopes openid profile email groups offline_access
OIDC client authentication None (public client)
Android environment Android / HyperOS
Successful authentication browser Firefox
Alternative browser tested Brave
QA application ID eu.opencloud.android.qa.debug
Compile SDK API 36
Minimum Android API 26
Build JDK Eclipse Temurin 17
Gradle 8.13
Test framework JUnit + Robolectric
Robolectric test API 28
Test/build date October 19, 2026

The OpenCloud server uses an external OIDC provider, with the built-in OpenCloud IDP disabled.

The issue was observed after upgrading OpenCloud from approximately version 7.5.0 to 8.1.0.

However, this does not establish that the server upgrade introduced the underlying bug. The investigation identifies a specific behavior in the Android application's account creation flow that is sufficient to reproduce the problem.

The application had previously worked in this environment.


Expected Behavior

When adding an OpenCloud account through an external OIDC provider:

  1. Android discovers the OIDC issuer, client ID, redirect URI, and configured scopes.
  2. Android requests the required scopes, including offline_access.
  3. The OIDC provider authenticates the user.
  4. If offline access requires explicit user consent, the authorization flow requests that consent.
  5. Android exchanges the authorization code using PKCE S256.
  6. The provider returns the tokens appropriate for the granted scopes, including a refresh token if offline access is granted.
  7. Android completes account creation and opens the authenticated account.
  8. The application can subsequently obtain new access tokens using the granted refresh token.

If the application depends on a refresh token, its initial OIDC authorization flow should support obtaining any required consent for offline_access.


Actual Behavior

With the official, unmodified OpenCloud Android 1.2.5 application:

  1. Open the Android application.
  2. Enter the OpenCloud server URL.
  3. Start adding a new account.
  4. The application discovers the correct external OIDC issuer and client configuration.
  5. The browser opens the VoidAuth login page.
  6. Authentication, including MFA where applicable, succeeds.
  7. VoidAuth redirects to the registered Android callback.
  8. The application attempts to complete account creation.
  9. Account creation fails with:
invalid refresh token

The issue persisted after:

  • Clearing the Android application's data.
  • Uninstalling and reinstalling the application.
  • Performing a completely fresh account setup.
  • Testing different authentication browsers.
  • Verifying the external OIDC client configuration.
  • Correcting the OpenCloud WebFinger scope representation.
  • Confirming that Android actually requests offline_access.

The error is reproducible with the unmodified Android application.


OIDC Client Configuration

The VoidAuth OIDC application is configured as follows:

Name:                  Opencloud Android
Client ID:             OpenCloudAndroid
Authentication method: None (Public)
PKCE:                  Required
Redirect URI:          oc://android.opencloud.eu
Response type:         code
Grant types:           authorization_code, refresh_token

Requested scopes:

openid profile email groups offline_access

The Android client is a public client using Authorization Code Flow with PKCE S256.

No client secret is required.

The refresh_token grant is enabled in VoidAuth.

There are no separate per-client settings in this VoidAuth installation for refresh-token lifetime, token rotation, or offline-access policy.


Investigation and Reproduction

1. Verified OpenCloud WebFinger configuration

The first investigation focused on the Android OIDC environment variables in OpenCloud.

The original scope configuration was:

WEBFINGER_ANDROID_OIDC_CLIENT_SCOPES=openid profile email groups offline_access

The WebFinger endpoint returned:

[
  "openid profile email groups offline_access"
]

This represented the scopes as one combined array element instead of individual scope values.

The environment variable was changed to the comma-separated form:

WEBFINGER_ANDROID_OIDC_CLIENT_SCOPES=openid,profile,email,groups,offline_access

After recreating the OpenCloud container, the WebFinger endpoint correctly returned:

[
  "openid",
  "profile",
  "email",
  "groups",
  "offline_access"
]

The relevant WebFinger configuration became:

{
  "properties": {
    "http://opencloud.eu/ns/oidc/client_id": "OpenCloudAndroid",
    "http://opencloud.eu/ns/oidc/scopes": [
      "openid",
      "profile",
      "email",
      "groups",
      "offline_access"
    ]
  },
  "links": [
    {
      "rel": "http://openid.net/specs/connect/1.0/issuer",
      "href": "https://<voidauth-host>/oidc"
    }
  ]
}

The endpoint was queried with the Android platform parameter:

curl -fsSG 'https://<opencloud-host>/.well-known/webfinger' \
  --data-urlencode 'resource=https://<opencloud-host>' \
  --data-urlencode 'rel=http://openid.net/specs/connect/1.0/issuer' \
  --data-urlencode 'platform=android' \
  | jq '.properties["http://opencloud.eu/ns/oidc/scopes"]'

Result: The scope array was corrected, but the original Android application still failed with invalid refresh token.

Therefore, the initial WebFinger formatting issue was not the cause.

After successfully testing the patched Android APK (described further in the issue), I reverted the OpenCloud environment variable to its original space-separated value:

WEBFINGER_ANDROID_OIDC_CLIENT_SCOPES=openid profile email groups offline_access

The patched Android application still logs in successfully.

This confirms that changing the WebFinger scope configuration to comma-separated values was not required to resolve the authentication failure in my environment.

The original Android application already requested all scopes correctly, including offline_access, as verified in Android Logcat.


2. Captured the actual OIDC authorization request from Android

I used ADB/Logcat to inspect the authorization URL generated by the official OpenCloud Android application.

The relevant parameters were:

client_id=OpenCloudAndroid
response_type=code
redirect_uri=oc://android.opencloud.eu
scope=openid profile email groups offline_access
prompt=login
code_challenge_method=S256
code_challenge=<redacted>
state=<redacted>

This proved that:

  • The correct Android OIDC client ID was used.
  • The redirect URI was correct.
  • offline_access was included in the authorization request.
  • PKCE S256 was used.
  • The application sent prompt=login.
  • The application did not include consent in the initial authorization request.

This was an important finding because it ruled out the hypothesis that Android was simply forgetting to request offline_access.

The problem was not the absence of the scope in the authorization request.


3. Inspected the provider-side authentication flow

VoidAuth logs showed the following sequence during an Android login:

GET  /oidc/.well-known/openid-configuration  -> 200
GET  /oidc/auth                             -> 303
OIDC authentication / interaction            -> successful
Redirect to oc://android.opencloud.eu        -> 303
POST /oidc/token                            -> 200
GET  /oidc/me                               -> 200

Authentication and the authorization code exchange succeeded.

However, the response status 200 does not prove that a refresh token was included in the JSON response.

This distinction turned out to be critical.

The token endpoint can successfully issue access and ID tokens without granting offline access.


4. Created an independent OIDC/PKCE diagnostic test

To determine whether VoidAuth was issuing refresh tokens, I created a Python test that implemented the Authorization Code Flow with PKCE S256.

The test used:

  • OpenID Connect discovery.
  • A dynamically generated authorization URL.
  • Randomly generated state.
  • Random PKCE verifier.
  • SHA-256 PKCE challenge.
  • Authorization Code Flow.
  • HTTPS token exchange.
  • The configured public client ID and redirect URI.

The script intentionally reported only whether token fields were present.

It did not print the actual access, ID, or refresh tokens.

Initial test with a temporary OIDC client

A temporary VoidAuth client was created:

Client ID:    OIDCRefreshTest
Client type:  Public
Redirect URI: http://127.0.0.1:8765/callback
PKCE:         Required
Grant types:  authorization_code, refresh_token

Because the Linux server was headless, a Windows browser was connected to the local callback listener using an SSH tunnel.

The test succeeded:

=== TOKEN RESPONSE ===
HTTP-Status: 200
access_token vorhanden: True
id_token vorhanden: True
refresh_token vorhanden: True
token_type: Bearer
expires_in: 3600
scope: openid profile email groups

Conclusion: VoidAuth v1.16.0 was capable of issuing refresh tokens.

However, that test used a different client ID and redirect URI, so it did not yet explain the problem with OpenCloudAndroid.


5. Tested the actual production Android OIDC client

The Python test was adapted to use the existing Android client without changing the production client configuration:

Client ID:     OpenCloudAndroid
Redirect URI:  oc://android.opencloud.eu
Flow:          authorization_code
PKCE:          S256
Scopes:        openid profile email groups offline_access

The authorization code was obtained through the normal VoidAuth browser authentication flow.

Since the browser on Windows was not registered to handle the Android-specific oc:// URI, the redirect Location header was inspected in Firefox Developer Tools.

The callback URL was passed directly to the local Python script, which then performed the token exchange.

Authorization codes, cookies, PKCE values, and session credentials are intentionally omitted from this issue.

Some early manual attempts returned:

HTTP-Status: 400
OIDC-Fehler: invalid_grant

Those attempts were inconclusive regarding refresh-token issuance because the authorization code exchange itself failed.

Subsequent fresh login attempts successfully completed the authorization code exchange and provided the decisive comparison below.


Controlled OIDC Tests: Consent vs. Refresh Token Issuance

All three decisive tests used the same production OIDC client:

Client ID:     OpenCloudAndroid
Redirect URI:  oc://android.opencloud.eu
Flow:          authorization_code
PKCE:          S256
Scopes:        openid profile email groups offline_access

The authorization request's prompt value was varied between the tests.

Test A: prompt=login

This reproduces the authorization request generated by the unmodified Android application during initial account creation.

Authorization request:

response_type=code
client_id=OpenCloudAndroid
scope=openid profile email groups offline_access
prompt=login
code_challenge_method=S256

Token response:

=== TOKEN RESPONSE ===
HTTP-Status: 200
access_token vorhanden: True
id_token vorhanden: True
refresh_token vorhanden: False
token_type: Bearer
expires_in: 3600
scope: openid profile email groups

Result: Authorization succeeded, but no refresh token was issued.

The token response also did not include offline_access in its returned scope string.

This matches the missing-refresh-token condition observed with the official Android application.


Test B: prompt=consent

The authorization request was changed to:

prompt=consent

Token response:

=== TOKEN RESPONSE ===
HTTP-Status: 200
access_token vorhanden: True
id_token vorhanden: True
refresh_token vorhanden: True
token_type: Bearer
expires_in: 3600
scope: openid profile email groups offline_access

Result: Successful. A refresh token was issued.

VoidAuth displayed the application's consent screen.

After consent was granted, the response included a refresh token and reported offline_access among the granted scopes.


Test C: prompt=login consent

The authorization request was changed to:

prompt=login consent

Token response:

=== TOKEN RESPONSE ===
HTTP-Status: 200
access_token vorhanden: True
id_token vorhanden: True
refresh_token vorhanden: True
token_type: Bearer
expires_in: 3600
scope: openid profile email groups offline_access

Result: Successful. A refresh token was issued.

This was the most relevant test because it preserves the application's existing reauthentication request while also requesting consent.


Comparison of All Three Tests

Authorization prompt Token endpoint Access token ID token Refresh token offline_access in returned scope
login 200 Yes Yes No No
consent 200 Yes Yes Yes Yes
login consent 200 Yes Yes Yes Yes

The tests demonstrate that VoidAuth v1.16.0 grants offline access for this client when the authorization request includes consent.

Without the required consent, VoidAuth successfully authenticates the user but does not grant offline access.

The tests provide strong evidence that the application's initial authorization prompt is responsible for the missing refresh token in this environment.


OpenID Connect Specification

The relevant specification is:

OpenID Connect Core 1.0, Section 11 — Offline Access

https://openid.net/specs/openid-connect-core-1_0.html#OfflineAccess

When requesting offline_access, the specification requires prompt to include consent unless other conditions permitting offline access have already been satisfied.

If neither the required explicit consent nor another sufficient condition exists, the authorization server must ignore the offline_access request.

The distinction is:

prompt=login

Requests reauthentication.

prompt=consent

Requests user consent.

prompt=login consent

Requests both reauthentication and consent.

VoidAuth's observed behavior is consistent with these OIDC requirements.

This is not a request to make an OIDC provider issue refresh tokens unconditionally.

Instead, the Android application's initial authorization flow should obtain the consent required to grant the offline access on which the application depends.


Root Cause in OpenCloud Android

The relevant application code is in:

opencloudApp/src/main/java/eu/opencloud/android/presentation/authentication/LoginActivity.kt

Method:

performGetAuthorizationCodeRequest()

Around line 888, the original implementation chooses the prompt argument using:

prompt = if (!oidcSupported) "" else if (loginAction == ACTION_CREATE) "login"
else mdmProvider.getBrandingString(
    CONFIGURATION_OAUTH2_OPEN_ID_PROMPT,
    R.string.oauth2_openid_prompt
),

The problematic branch is:

loginAction == ACTION_CREATE

When creating a new account, the application forces:

login

regardless of the requested scopes.

When other login actions are performed, the application uses the MDM/branding-configured prompt.

The default value in:

opencloudApp/src/main/res/values/setup.xml

is:

select_account consent

Therefore, the application already supports consent-related prompts for other authentication contexts.

However, the initial account creation flow bypasses the configurable prompt and always uses login.

Why this matters

A provider may correctly refuse offline access if the required consent has not been obtained.

In that case:

  1. The requested scopes contain offline_access.
  2. The authorization request contains only prompt=login.
  3. Authentication succeeds.
  4. The token endpoint returns HTTP 200.
  5. Access and ID tokens are issued.
  6. The provider does not grant offline access.
  7. No refresh token is issued.
  8. Android account creation fails with invalid refresh token.

The initial account creation flow should not assume that successful authentication automatically authorizes offline access.


Proposed Minimal Fix

The proposed change makes prompt selection depend on whether the requested scopes contain the exact offline_access token.

Condition Prompt
OIDC unsupported Empty
ACTION_CREATE with offline_access login consent
ACTION_CREATE without offline_access login
Other authentication actions Existing configured/branding value

This preserves the original authentication behavior where offline access is not requested.

It also preserves the existing MDM/branding behavior for login actions other than ACTION_CREATE.

The following are unchanged:

  • OIDC issuer discovery
  • Client ID
  • Redirect URI
  • Authorization Code Flow
  • PKCE generation
  • State handling
  • Scope configuration
  • Token exchange
  • Token storage
  • Refresh-token processing
  • Server-side configuration

No change to VoidAuth or OpenCloud server configuration is required for this patch.


Implemented Source Code Changes

I used Codex to make the change and build a test application.

The OIDC behavior is modified in two existing source files, with a third file added for automated tests.

An additional one-line build-environment fix was required because the local source directory did not contain Git metadata.

1. LoginActivity.kt

Actual diff:

diff --git a/opencloudApp/src/main/java/eu/opencloud/android/presentation/authentication/LoginActivity.kt b/opencloudApp/src/main/java/eu/opencloud/android/presentation/authentication/LoginActivity.kt
index 7583769..310d9a6 100644
--- a/opencloudApp/src/main/java/eu/opencloud/android/presentation/authentication/LoginActivity.kt
+++ b/opencloudApp/src/main/java/eu/opencloud/android/presentation/authentication/LoginActivity.kt
@@ -885,7 +885,7 @@ class LoginActivity : AppCompatActivity(), SslUntrustedCertDialog(), ...
             clientId = clientId,
             responseType = ResponseType.CODE.string,
             scope = scope,
-            prompt = if (!oidcSupported) "" else if (loginAction == ACTION_CREATE) "login"
+            prompt = if (!oidcSupported) "" else if (loginAction == ACTION_CREATE) OAuthUtils.getCreateAccountPrompt(scope)
             else mdmProvider.getBrandingString(CONFIGURATION_OAUTH2_OPEN_ID_PROMPT, R.string.oauth2_openid_prompt),
             codeChallenge = authenticationViewModel.codeChallenge,
             state = authenticationViewModel.oidcState,

The change replaces the hardcoded login value during account creation with a scope-aware helper.

No other authentication path is modified.


2. OAuthUtils.kt

Actual diff:

diff --git a/opencloudApp/src/main/java/eu/opencloud/android/presentation/authentication/oauth/OAuthUtils.kt b/opencloudApp/src/main/java/eu/opencloud/android/presentation/authentication/oauth/OAuthUtils.kt
index 393a4ec..0a2bad5 100644
--- a/opencloudApp/src/main/java/eu/opencloud/android/presentation/authentication/oauth/OAuthUtils.kt
+++ b/opencloudApp/src/main/java/eu/opencloud/android/presentation/authentication/oauth/OAuthUtils.kt
@@ -96,6 +96,10 @@ class OAuthUtils {
             return "Basic " + Base64.encodeToString(credentials.toByteArray(), Base64.NO_WRAP)
         }

+        fun getCreateAccountPrompt(scope: String): String =
+            // Request offline consent while still requiring fresh authentication.
+            if ("offline_access" in scope.split(' ')) "login consent" else "login"
+
         fun buildAuthorizationRequest(
             authorizationEndpoint: Uri,
             redirectUri: String,

The helper returns:

"login consent"

when the scope string includes the exact offline_access token.

Otherwise, it returns:

"login"

This deliberately avoids incorrect substring matches such as:

not_offline_access
offline_access_extra

The existing OAuthUtils.buildAuthorizationRequest() implementation remains unchanged.


3. Added OAuthPromptTest.kt

New test file:

opencloudApp/src/test/java/eu/opencloud/android/presentation/authentication/oauth/OAuthPromptTest.kt

Source:

package eu.opencloud.android.presentation.authentication.oauth

import android.net.Uri
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config

@RunWith(RobolectricTestRunner::class)
@Config(manifest = Config.NONE, sdk = [28])
class OAuthPromptTest {

    @Test
    fun offlineAccessRequiresLoginAndConsent() {
        assertEquals(
            "login consent",
            OAuthUtils.getCreateAccountPrompt(
                "openid profile email groups offline_access"
            )
        )
        assertEquals(
            "login consent",
            OAuthUtils.getCreateAccountPrompt(
                " offline_access  openid "
            )
        )
    }

    @Test
    fun otherScopesKeepLogin() {
        for (scope in listOf(
            "",
            "openid profile email",
            "openid not_offline_access",
            "offline_access_extra"
        )) {
            assertEquals(
                "login",
                OAuthUtils.getCreateAccountPrompt(scope)
            )
        }
    }

    @Test
    fun authorizationRequestEncodesOnePromptAndPreservesPkceAndRedirect() {
        val scope = "openid profile email groups offline_access"

        val uri = OAuthUtils.buildAuthorizationRequest(
            authorizationEndpoint = Uri.parse(
                "https://idp.example/authorize?existing=value"
            ),
            redirectUri = "oc://android.opencloud.eu",
            clientId = "OpenCloudAndroid",
            responseType = "code",
            scope = scope,
            prompt = OAuthUtils.getCreateAccountPrompt(scope),
            codeChallenge = "test-challenge",
            state = "test-state",
            username = null,
            sendLoginHintAndUser = false,
        )

        assertEquals(
            listOf("login consent"),
            uri.getQueryParameters("prompt")
        )
        assertTrue(
            uri.encodedQuery!!.contains("prompt=login%20consent")
        )
        assertEquals(
            "oc://android.opencloud.eu",
            uri.getQueryParameter("redirect_uri")
        )
        assertEquals(
            "OpenCloudAndroid",
            uri.getQueryParameter("client_id")
        )
        assertEquals(
            scope,
            uri.getQueryParameter("scope")
        )
        assertEquals(
            "S256",
            uri.getQueryParameter("code_challenge_method")
        )
        assertEquals(
            "test-challenge",
            uri.getQueryParameter("code_challenge")
        )
        assertEquals(
            "test-state",
            uri.getQueryParameter("state")
        )
        assertEquals(
            "value",
            uri.getQueryParameter("existing")
        )

        println("Authorization request under test: $uri")
    }
}

Unit-test coverage

The tests verify:

  1. offline_access causes login consent to be selected.
  2. Extra spaces in the supplied scope string do not prevent detecting offline_access.
  3. Scope lists without offline_access preserve login.
  4. Similar but different scope names are not treated as offline_access.
  5. The actual authorization URL builder correctly encodes the new prompt.
  6. The decoded URL contains one prompt parameter with the value login consent.
  7. The URL preserves the expected client ID.
  8. The URL preserves the registered redirect URI.
  9. The URL preserves the requested scopes.
  10. The URL preserves PKCE S256 and the code challenge.
  11. The URL preserves state.
  12. The URL preserves an unrelated existing query parameter.

Important limitation of the URL-builder test

The test uses an authorization endpoint containing:

?existing=value

but no pre-existing prompt parameter.

It confirms that one prompt parameter is generated in this case.

It does not establish how duplicate prompt parameters would be handled if the endpoint URL already contained a prompt parameter.

The existing builder behavior for pre-existing prompt parameters was not modified by this patch.


Automated Test Execution — PASSED

The QA build and Robolectric tests were successfully executed on October 19, 2026.

The three targeted tests were run using Robolectric on API 28.

JUnit test summary

Test suite: OAuthPromptTest
Tests:      3
Passed:     3
Failures:   0
Errors:     0
Skipped:    0

All three tests passed:

otherScopesKeepLogin
authorizationRequestEncodesOnePromptAndPreservesPkceAndRedirect
offlineAccessRequiresLoginAndConsent

Actual JUnit XML result

<?xml version="1.0" encoding="UTF-8"?>
<testsuite name="eu.opencloud.android.presentation.authentication.oauth.OAuthPromptTest"
           tests="3"
           skipped="0"
           failures="0"
           errors="0"
           timestamp="2026-10-19T17:44:13.041Z"
           hostname="BLINGBLING-RTX"
           time="3.072">
  <properties/>
  <testcase name="otherScopesKeepLogin"
            classname="eu.opencloud.android.presentation.authentication.oauth.OAuthPromptTest"
            time="3.013"/>
  <testcase name="authorizationRequestEncodesOnePromptAndPreservesPkceAndRedirect"
            classname="eu.opencloud.android.presentation.authentication.oauth.OAuthPromptTest"
            time="0.037"/>
  <testcase name="offlineAccessRequiresLoginAndConsent"
            classname="eu.opencloud.android.presentation.authentication.oauth.OAuthPromptTest"
            time="0.022"/>
</testsuite>

The generated test report also contains the authorization request produced by the actual OAuthUtils implementation.

Authorization URL generated during testing

https://idp.example/authorize?existing=value&redirect_uri=oc%3A%2F%2Fandroid.opencloud.eu&client_id=OpenCloudAndroid&response_type=code&scope=openid%20profile%20email%20groups%20offline_access&prompt=login%20consent&code_challenge=test-challenge&code_challenge_method=S256&state=test-state

The important generated parameter is:

prompt=login%20consent

This decodes to:

prompt=login consent

The test also confirms:

redirect_uri=oc://android.opencloud.eu
client_id=OpenCloudAndroid
response_type=code
code_challenge_method=S256

Robolectric SDK warning

The test runner reported:

[Robolectric] WARN: Android SDK 36 requires Java 21 (have Java 17).
Tests won't be run on SDK 36 unless explicitly requested.

This warning did not prevent the targeted tests from executing.

The tests were explicitly configured for Robolectric API 28 and completed successfully using Java 17.

The APK itself was built with compile SDK API 36.

All three targeted automated tests passed.


Verified QA-Debug APK Build

The modified Android application was successfully built as a signed QA/debug APK.

Build artifact

Property Value
APK filename OpenCloud_1.2.5-qa-debug.apk
Version 1.2.5
Version code 11
Application ID eu.opencloud.android.qa.debug
APK size 17,250,541 bytes
Compile SDK API 36
Minimum Android API 26
JDK Eclipse Temurin 17.0.20
Gradle 8.13
Signature Android Debug
APK Signature Scheme v2
Signature verification Passed

The APK was verified using apksigner.

Certificate subject:

CN=Android Debug

SHA-256 checksum

BBDAE49CE22165015459DFD764603AB77830B7B925B1C6EC619BA32847E20C30

This checksum identifies the exact local APK artifact used for testing.

The APK is a debug-signed QA build, not an official OpenCloud release.

Local build configuration

The local Windows build environment contained:

JDK:          Eclipse Temurin 17.0.20
Android SDK:  API 36
Build Tools:  35.0.0
Gradle:       8.13

Additional installed SDK components included:

  • Android Platform-Tools
  • Android SDK Command-line Tools
  • Android SDK Platform 36

A local PowerShell build script executed:

assembleQaDebug
testQaDebugUnitTest

with a test filter selecting OAuthPromptTest.

Both the build and the targeted test run completed successfully.


Real-Device End-to-End Test — PASSED

The modified APK was installed and successfully tested on a real Android device.

This is the most important functional validation of the proposed fix.

The test did not stop at compiling the application or inspecting a generated authorization URL.

It involved installing the modified OpenCloud Android application and completing the real OIDC login against the existing OpenCloud/VoidAuth installation.

Test procedure

  1. Build the modified OpenCloud Android QA/debug APK.
  2. Install it on the Android device.
  3. Launch OpenCloud QA.
  4. Start adding the existing OpenCloud server as a new account.
  5. Start the VoidAuth OIDC authentication.
  6. Complete the authentication in Firefox.
  7. Return to the OpenCloud QA application using the registered Android callback.
  8. Complete account creation.

Actual result

The account was added successfully, and I was logged into OpenCloud.

The original application had consistently failed with:

invalid refresh token

The modified application successfully completed the authentication flow using the existing server and OIDC provider.

The test used:

OpenCloud server: 8.1.0
OIDC provider:    VoidAuth v1.16.0
OIDC client ID:   OpenCloudAndroid
Redirect URI:     oc://android.opencloud.eu
Requested scopes: openid profile email groups offline_access

The functional Android change was the scope-aware addition of consent to the account creation prompt.

No change to the production OIDC client ID, registered redirect URI, PKCE handling, token handling, or server-side OIDC configuration was required for this successful test.

Validation status

Test Result
Original Android 1.2.5, fresh installation Failed
Original Android 1.2.5, cleared app data Failed
Original Android 1.2.5, corrected WebFinger scopes Failed
Independent OIDC test with prompt=login No refresh token
Independent OIDC test with prompt=consent Refresh token issued
Independent OIDC test with prompt=login consent Refresh token issued
QA/debug APK compilation Passed
Debug APK signing Passed
APK signature verification Passed
Robolectric test: offlineAccessRequiresLoginAndConsent Passed
Robolectric test: otherScopesKeepLogin Passed
Robolectric test: authorizationRequestEncodesOnePromptAndPreservesPkceAndRedirect Passed
Actual Android device login with modified APK Passed
Long-term refresh after access-token expiration Not yet separately verified

Important validation boundary

The successful real-device login demonstrates that the proposed patch resolves initial account creation and authentication in this environment.

The long-term token refresh lifecycle, including automatic refresh after access-token expiration and possible refresh-token rotation, has not yet been separately tested over an extended period.

That follow-up validation would be useful, but it does not change the confirmed result that the modified application can successfully complete an OIDC login where the original application fails.


Separate Browser Issue: Brave and Custom Redirect Schemes

During the investigation, another issue was observed with Brave.

On Android, Brave had difficulty completing the redirect back to the OpenCloud application using the custom URI scheme:

oc://android.opencloud.eu

A related custom-protocol handling problem was observed with Brave on Windows during the manual OIDC tests.

Firefox was used to complete the successful modified-APK login on Android.

This appears to be a separate issue involving browser handling of custom URI schemes and/or application handoff.

It should not be conflated with the missing refresh-token problem.

The OIDC consent behavior was independently demonstrated using direct Python token exchanges, without requiring the Android application or its browser callback handling.

The modified application successfully logged in using Firefox.

I suggest tracking Brave-specific redirect handling separately rather than expanding this issue to cover both problems.


Additional Build-Environment Adjustment

Codex also applied a one-line change in:

opencloudApp/build.gradle

The original code assumed that the local source directory contained a Git remote named origin.

However, the source directory used for this build did not contain Git metadata.

The change was:

diff --git a/opencloudApp/build.gradle b/opencloudApp/build.gradle
index b5e2879..5461378 100644
--- a/opencloudApp/build.gradle
+++ b/opencloudApp/build.gradle
@@ -306,7 +306,7 @@ static def getGitOriginRemote() {
     def values = process.text.toString().trim().split("\\r\\n|\\n|\\r")

     def found = values.find { it.startsWith("origin") && it.endsWith("(push)") }
-    return found.replace("origin", "").replace("(push)", "").replace(".git", "").trim()
+    return found == null ? "" : found.replace("origin", "").replace("(push)", "").replace(".git", "").trim()
 }

 tasks.withType(io.gitlab.arturbosch.detekt.Detekt).configureEach {

This null check allowed the local build process to handle the missing Git remote.

It is not part of the OIDC authentication fix.

For an upstream pull request, this build-environment adjustment can be separated or omitted unless maintainers consider it independently useful.

The actual OIDC fix consists of the changes to LoginActivity.kt, OAuthUtils.kt, and the added OAuthPromptTest.kt tests.


Build and Test Artifacts Available

The local test package contains the following artifacts:

consent-fix/
├── consent-fix.patch
├── original/
├── build-jdk17.log
├── OAuthPromptTest-results.xml
├── apk-signature.txt
├── README-initial-build-blocked.md
└── tools/
    └── gradle-8.13/

Descriptions:

Artifact Description
consent-fix.patch Complete diff containing the OIDC fix, tests, and local build adjustment
original/ Original unmodified source files
build-jdk17.log Successful build and targeted test execution
OAuthPromptTest-results.xml JUnit XML report confirming three passing tests
apk-signature.txt APK signature verification results
README-initial-build-blocked.md Historical notes about the initial build environment issue
OpenCloud_1.2.5-qa-debug.apk Successfully built and manually tested QA/debug APK

The patch, test report, and build logs can be provided to maintainers if needed.

For upstream review, the minimal source patch and test cases are the most important artifacts.


Why This Is Not Necessarily VoidAuth-Specific

The Android application's current ACTION_CREATE implementation assumes that:

scope=openid ... offline_access
prompt=login

is sufficient for the provider to issue a refresh token.

This assumption does not hold for every OIDC provider.

A provider may require explicit consent or another sufficient condition before granting offline access.

The resulting failure can be confusing because the authorization flow may otherwise succeed:

  • User authentication succeeds.
  • MFA succeeds.
  • The authorization code is valid.
  • PKCE verification succeeds.
  • The token endpoint returns HTTP 200.
  • An access token is present.
  • An ID token is present.
  • The refresh token is missing.
  • Android reports invalid refresh token.

Therefore, other standards-compliant OIDC providers could potentially be affected by the same Android account creation behavior.

The root issue is not that VoidAuth refuses to issue refresh tokens in general.

The root issue is that OpenCloud Android requests offline access without requesting the consent that the provider requires for the initial account creation flow.

This also explains why normal web authentication and the OpenCloud Desktop client can continue working while initial Android account creation fails.


Suggested Upstream Resolution

I suggest the following changes:

  • Update the ACTION_CREATE OIDC flow to request consent when the exact offline_access scope is present.
  • Preserve login when offline_access is absent.
  • Preserve the existing MDM/branding-configurable prompt for other authentication actions.
  • Preserve the existing PKCE, redirect URI, state, client ID, and token handling.
  • Add automated tests for scope-aware prompt selection.
  • Test authorization URL encoding to ensure the intended prompt value is transmitted.
  • Verify the implementation with a provider that requires explicit consent for offline access.
  • Consider improving the diagnostic message when token exchange succeeds but no refresh token is issued.
  • Keep browser-specific custom URI redirect failures in a separate issue.

The minimal patch described here is already implemented and has been validated through automated tests and a real-device login.

A larger authentication refactor is not required to reproduce or address the demonstrated issue.

Maintainers may prefer a different internal implementation, but the functional requirement is clear:

The initial authorization request must support obtaining consent when offline access is requested and such consent is required.


Related Links

OpenID Connect specification

OpenCloud Android source code

Related VoidAuth issue

The VoidAuth issue was originally created before the root cause had been isolated.

The controlled tests now indicate that VoidAuth's refusal to grant offline access without the required consent is consistent with the OIDC specification.


Final Conclusion

The investigation isolated the failure to a specific difference in the authorization request generated during initial Android account creation.

Unmodified Android application

scope=openid profile email groups offline_access
prompt=login

Independent token-exchange result:

HTTP-Status: 200

access_token:  present
id_token:      present
refresh_token: absent

Granted scopes:
openid profile email groups

Actual Android result:

invalid refresh token

Initial account creation fails.

Modified Android application

scope=openid profile email groups offline_access
prompt=login consent

Independent token-exchange result:

HTTP-Status: 200

access_token:  present
id_token:      present
refresh_token: present

Granted scopes:
openid profile email groups offline_access

Automated validation:

Robolectric tests: 3 passed
Failures:          0
Errors:            0
Skipped:           0

QA/debug APK build: successful
APK signature:      verified

Actual Android result:

OIDC authentication successful
OpenCloud account successfully added
User successfully logged in

Initial account creation succeeds.

The working patch is small, scope-aware, preserves existing behavior where offline access is not requested, and has been verified through both automated tests and a successful real-device login.

This provides a reproducible issue, a technically grounded explanation, a concrete minimal fix, and a working proof of concept.

I would be happy to provide the patch, relevant test/build artifacts, or prepare a pull request.

Thank you for considering this fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions