Adding support for cloudflare access token#445
Adding support for cloudflare access token#445pepitoria wants to merge 1 commit intogotify:masterfrom
Conversation
|
Hi guys, I have opened this PR out of my own need. I have my gotify server exposed through cloudflare tunnels but since for the paranoid of us that is not enough to be comfy, I added access control from cloudflare. This PR adds that in the app to handle the headers needed for the app to work. I also added a cloudflare-tunnel-access-setup.md in the root of the project that I really do not intent to make it to the app code in master but your you guys (maintainers) to check out if you want. Disclaimer: I used claude code to implement this feature but I have also have 15 years of professional android development experience and I have reviewed all changes so I hope this is not an issue. |
|
Have you considered using mutual TLS? https://developers.cloudflare.com/learning-paths/mtls/mtls-cloudflare-access/ This should be more secure than just some extra secrets in the headers and is already supported by the app. |
|
to be honest, no, I did not considered it because I did not know about them! I will check it out at some point, for now I have the access token working with my gotify domain in cloudflare and the app seems to be running fine (I installed on device from android studio). Thanks for the suggestion! |
Add Cloudflare Access Token Headers Support
Summary
CF-Access-Client-IdandCF-Access-Client-SecretheadersMotivation
Users whose Gotify servers are protected by Cloudflare Access could not use the Android app at all — the login request itself would be blocked without the CF headers. This change adds CF Access configuration to the Advanced Dialog on the login screen, following the same pattern used for SSL/certificate settings.
Changes
New files
CfAccessSettings.ktenabled,clientId, andclientSecretapi/CloudflareAccessInterceptor.ktCF-Access-Client-IdandCF-Access-Client-Secretheaders to every requestModified files
Settings.ktcfAccessEnabled,cfAccessClientId,cfAccessClientSecretproperties,cfAccessSettings()helper, and cleanup inclear()login/AdvancedDialog.ktres/layout/advanced_settings_dialog.xmlTextInputLayoutfields for CF credentialslogin/LoginActivity.kttempCfAccessSettings()helper, passes CF settings toClientFactoryduring URL check and login, persists credentials on successful loginapi/ClientFactory.ktcfAccessSettingsparameter todefaultClient(),versionApi(),basicAuth(), andunauthorized(); applies interceptor when enabledservice/WebSocketConnection.ktCfAccessSettingsparameter, applies interceptor to the OkHttpClient used for WebSocket connectionsservice/WebSocketService.ktsettings.cfAccessSettings()when creatingWebSocketConnectionCoilInstance.ktCfAccessSettingsin cache key to invalidate when credentials changeres/xml/root_preferences.xmlEditTextPreferencefields (dependency-linked to the switch)settings/SettingsActivity.ktSettingsclass (custom SharedPreferences), triggers WebSocket restart on changeres/values/strings.xmlHow it works
Settingsclass.ClientFactory), WebSocket connections (WebSocketConnection), and image loading (CoilInstance).Test plan
./gradlew assembleDebug