├── Example
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── strings.xml
│ │ │ ├── colors.xml
│ │ │ └── styles.xml
│ │ ├── mipmap-hdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-mdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-xxxhdpi
│ │ │ ├── ic_launcher.png
│ │ │ └── ic_launcher_round.png
│ │ ├── mipmap-anydpi-v26
│ │ │ ├── ic_launcher.xml
│ │ │ └── ic_launcher_round.xml
│ │ ├── layout
│ │ │ ├── fragment_main_activity.xml
│ │ │ ├── fragment_main.xml
│ │ │ ├── activity_login.xml
│ │ │ └── activity_main.xml
│ │ ├── drawable-v24
│ │ │ └── ic_launcher_foreground.xml
│ │ └── drawable
│ │ │ └── ic_launcher_background.xml
│ │ ├── java
│ │ └── com
│ │ │ └── infomaniak
│ │ │ └── login
│ │ │ └── example
│ │ │ ├── FragmentMainActivity.kt
│ │ │ ├── FragmentMainFragment.kt
│ │ │ ├── LoginActivity.kt
│ │ │ └── MainActivity.kt
│ │ └── AndroidManifest.xml
├── proguard-rules.pro
└── build.gradle
├── Library
├── .gitignore
├── src
│ └── main
│ │ ├── res
│ │ ├── values
│ │ │ ├── values.xml
│ │ │ └── strings.xml
│ │ ├── menu
│ │ │ └── webview_menu.xml
│ │ ├── values-es
│ │ │ └── strings.xml
│ │ ├── values-de
│ │ │ └── strings.xml
│ │ ├── values-it
│ │ │ └── strings.xml
│ │ ├── drawable
│ │ │ └── ic_baseline_close.xml
│ │ ├── values-fr
│ │ │ └── strings.xml
│ │ └── layout
│ │ │ └── activity_web_view_login.xml
│ │ └── java
│ │ └── com
│ │ └── infomaniak
│ │ └── lib
│ │ └── login
│ │ ├── ApiToken.kt
│ │ ├── WebViewUtils.kt
│ │ ├── ProgressWebChromeClient.kt
│ │ ├── ext
│ │ ├── BindingExt.kt
│ │ └── OkHttpClientExt.kt
│ │ ├── WebViewLoginActivity.kt
│ │ ├── WebViewCreateAccountActivity.kt
│ │ ├── LoginWebViewClient.kt
│ │ └── InfomaniakLogin.kt
├── proguard-rules.pro
└── build.gradle
├── jitpack.yml
├── gradle
├── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
└── libs.versions.toml
├── .idea
├── copyright
│ ├── profiles_settings.xml
│ └── Infomaniak_Open_Source.xml
└── codeStyles
│ ├── codeStyleConfig.xml
│ └── Project.xml
├── .gitignore
├── gradle.properties
├── settings.gradle
├── gradlew.bat
├── README.md
├── gradlew
└── LICENSE
/Example/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/Library/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/jitpack.yml:
--------------------------------------------------------------------------------
1 | jdk:
2 | - openjdk17
3 |
--------------------------------------------------------------------------------
/Example/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 | Login Example
3 |
4 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/infomaniak/android-login/master/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/.idea/copyright/profiles_settings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *.iml
2 | .gradle
3 | /local.properties
4 | /.idea
5 | .DS_Store
6 | /build
7 | /captures
8 | .externalNativeBuild
9 | .cxx
10 |
--------------------------------------------------------------------------------
/Example/src/main/res/mipmap-hdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/infomaniak/android-login/master/Example/src/main/res/mipmap-hdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Example/src/main/res/mipmap-mdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/infomaniak/android-login/master/Example/src/main/res/mipmap-mdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Example/src/main/res/mipmap-xhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/infomaniak/android-login/master/Example/src/main/res/mipmap-xhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Example/src/main/res/mipmap-xxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/infomaniak/android-login/master/Example/src/main/res/mipmap-xxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Example/src/main/res/mipmap-xxxhdpi/ic_launcher.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/infomaniak/android-login/master/Example/src/main/res/mipmap-xxxhdpi/ic_launcher.png
--------------------------------------------------------------------------------
/Example/src/main/res/mipmap-hdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/infomaniak/android-login/master/Example/src/main/res/mipmap-hdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Example/src/main/res/mipmap-mdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/infomaniak/android-login/master/Example/src/main/res/mipmap-mdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Example/src/main/res/mipmap-xhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/infomaniak/android-login/master/Example/src/main/res/mipmap-xhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Example/src/main/res/mipmap-xxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/infomaniak/android-login/master/Example/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/Example/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/infomaniak/android-login/master/Example/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
--------------------------------------------------------------------------------
/.idea/codeStyles/codeStyleConfig.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | org.gradle.jvmargs=-Xmx1536m
2 | android.useAndroidX=true
3 | android.enableJetifier=true
4 | kotlin.code.style=official
5 | android.nonTransitiveRClass=false
6 | android.nonFinalResIds=false
7 |
--------------------------------------------------------------------------------
/Library/src/main/res/values/values.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Example/src/main/res/values/colors.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | #6200EE
4 | #3700B3
5 | #03DAC5
6 |
7 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Thu Dec 10 12:28:33 CET 2020
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.13-bin.zip
7 |
--------------------------------------------------------------------------------
/Example/src/main/res/mipmap-anydpi-v26/ic_launcher.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Example/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/Example/src/main/res/layout/fragment_main_activity.xml:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/Library/src/main/res/menu/webview_menu.xml:
--------------------------------------------------------------------------------
1 |
2 |
11 |
--------------------------------------------------------------------------------
/Library/src/main/res/values/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Access denied
4 |
5 | An error has occurred
6 | Internet connection problem
7 | Create an account
8 | Login
9 |
10 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | pluginManagement {
2 | repositories {
3 | gradlePluginPortal()
4 | google()
5 | mavenCentral()
6 | }
7 | }
8 |
9 | dependencyResolutionManagement {
10 | repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
11 | repositories {
12 | google()
13 | mavenCentral()
14 | }
15 | }
16 |
17 | rootProject.name = 'android-login'
18 | include ':Library', ':Example'
19 |
--------------------------------------------------------------------------------
/Library/src/main/res/values-es/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Acceso rechazado
4 |
5 | Se produjo un error
6 | Problema de conexión a Internet
7 | Crear una cuenta
8 | Ingresa en
9 |
10 |
--------------------------------------------------------------------------------
/Library/src/main/res/values-de/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Zugang verweigert
4 |
5 | Ein Fehler ist aufgetreten
6 | Internet-Verbindungsproblem
7 | Ein Konto erstellen
8 | Anmeldung
9 |
10 |
--------------------------------------------------------------------------------
/Library/src/main/res/values-it/strings.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | Accesso rifiutato
4 |
5 | Si è verificato un errore
6 | Problema di connessione a Internet
7 | Creare un account
8 | Accesso
9 |
10 |
--------------------------------------------------------------------------------
/Library/src/main/res/drawable/ic_baseline_close.xml:
--------------------------------------------------------------------------------
1 |
7 |
10 |
11 |
--------------------------------------------------------------------------------
/Example/src/main/java/com/infomaniak/login/example/FragmentMainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.infomaniak.login.example
2 |
3 | import android.os.Bundle
4 | import androidx.appcompat.app.AppCompatActivity
5 |
6 | class FragmentMainActivity : AppCompatActivity() {
7 |
8 | override fun onCreate(savedInstanceState: Bundle?) {
9 | super.onCreate(savedInstanceState)
10 | setContentView(R.layout.fragment_main_activity)
11 | if (savedInstanceState == null) {
12 | supportFragmentManager.beginTransaction()
13 | .replace(R.id.container, FragmentMainFragment.newInstance())
14 | .commitNow()
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/Library/src/main/java/com/infomaniak/lib/login/ApiToken.kt:
--------------------------------------------------------------------------------
1 | package com.infomaniak.lib.login
2 |
3 | import android.os.Parcelable
4 | import kotlinx.parcelize.Parcelize
5 | import kotlinx.serialization.SerialName
6 | import kotlinx.serialization.Serializable
7 |
8 | @Parcelize
9 | @Serializable
10 | data class ApiToken(
11 | @SerialName("access_token") val accessToken: String,
12 | @SerialName("refresh_token") val refreshToken: String? = null,
13 | @SerialName("token_type") val tokenType: String,
14 | @SerialName("expires_in") val expiresIn: Int = 7200,
15 | @SerialName("user_id") val userId: Int,
16 | @SerialName("scope") val scope: String? = null,
17 | @Transient var expiresAt: Long? = null
18 | ) : Parcelable
19 |
--------------------------------------------------------------------------------
/Example/src/main/res/values/styles.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
12 |
13 |
17 |
18 |
--------------------------------------------------------------------------------
/Example/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/Library/proguard-rules.pro:
--------------------------------------------------------------------------------
1 | # Add project specific ProGuard rules here.
2 | # You can control the set of applied configuration files using the
3 | # proguardFiles setting in build.gradle.
4 | #
5 | # For more details, see
6 | # http://developer.android.com/guide/developing/tools/proguard.html
7 |
8 | # If your project uses WebView with JS, uncomment the following
9 | # and specify the fully qualified class name to the JavaScript interface
10 | # class:
11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12 | # public *;
13 | #}
14 |
15 | # Uncomment this to preserve the line number information for
16 | # debugging stack traces.
17 | #-keepattributes SourceFile,LineNumberTable
18 |
19 | # If you keep the line number information, uncomment this to
20 | # hide the original source file name.
21 | #-renamesourcefileattribute SourceFile
22 |
--------------------------------------------------------------------------------
/Example/src/main/res/layout/fragment_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/.idea/copyright/Infomaniak_Open_Source.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/Library/src/main/java/com/infomaniak/lib/login/WebViewUtils.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak Login - Android
3 | * Copyright (C) 2023 Infomaniak Network SA
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.infomaniak.lib.login
19 |
20 | import android.webkit.CookieManager
21 |
22 | internal object WebViewUtils {
23 |
24 | fun flushAllCookies() {
25 | CookieManager.getInstance().removeAllCookies(null)
26 | CookieManager.getInstance().flush()
27 | }
28 |
29 | }
30 |
--------------------------------------------------------------------------------
/Library/src/main/res/values-fr/strings.xml:
--------------------------------------------------------------------------------
1 |
18 |
19 | Accès refusé
20 |
21 | Une erreur est survenue
22 | Problème de connexion internet
23 | Créer un compte
24 | Se connecter
25 |
26 |
--------------------------------------------------------------------------------
/Library/src/main/java/com/infomaniak/lib/login/ProgressWebChromeClient.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak Login - Android
3 | * Copyright (C) 2023 Infomaniak Network SA
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.infomaniak.lib.login
19 |
20 | import android.webkit.WebChromeClient
21 | import android.webkit.WebView
22 | import android.widget.ProgressBar
23 | import androidx.core.view.isGone
24 |
25 | class ProgressWebChromeClient(private val progressBar: ProgressBar) : WebChromeClient() {
26 |
27 | override fun onProgressChanged(view: WebView?, newProgress: Int) = with(progressBar) {
28 | progress = newProgress
29 | if (newProgress == 100) isGone = true
30 | }
31 |
32 | }
33 |
--------------------------------------------------------------------------------
/Library/src/main/java/com/infomaniak/lib/login/ext/BindingExt.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak Login - Android
3 | * Copyright (C) 2025 Infomaniak Network SA
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.infomaniak.lib.login.ext
19 |
20 | import androidx.core.view.ViewCompat
21 | import androidx.core.view.WindowInsetsCompat
22 | import androidx.core.view.updatePadding
23 | import com.infomaniak.lib.login.databinding.ActivityWebViewLoginBinding
24 |
25 | internal fun ActivityWebViewLoginBinding.handleEdgeToEdge() {
26 | ViewCompat.setOnApplyWindowInsetsListener(root) { view, insets ->
27 | val systemBar = insets.getInsets(WindowInsetsCompat.Type.systemBars())
28 | appBarLayout.updatePadding(top = systemBar.top)
29 | view.updatePadding(left = systemBar.left, right = systemBar.right, bottom = systemBar.bottom)
30 | WindowInsetsCompat.CONSUMED
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/gradle/libs.versions.toml:
--------------------------------------------------------------------------------
1 | [versions]
2 | agp = "8.12.0"
3 | appcompat = "1.7.0"
4 | browser = "1.8.0"
5 | constraintlayout = "2.2.1"
6 | gson = "2.12.1"
7 | kotlin = "2.2.0"
8 | kotlinxCoroutinesAndroid = "1.10.1"
9 | kotlinxSerializationJson = "1.8.1"
10 | lifecycleRuntimeKtx = "2.9.2"
11 | material = "1.12.0"
12 | okhttp = "4.12.0"
13 |
14 | [libraries]
15 | appcompat = { module = "androidx.appcompat:appcompat", version.ref = "appcompat" }
16 | browser = { module = "androidx.browser:browser", version.ref = "browser" }
17 | constraintlayout = { module = "androidx.constraintlayout:constraintlayout", version.ref = "constraintlayout" }
18 | gson = { module = "com.google.code.gson:gson", version.ref = "gson" }
19 | kotlin-stdlib-jdk8 = { module = "org.jetbrains.kotlin:kotlin-stdlib-jdk8", version.ref = "kotlin" }
20 | kotlinx-coroutines-android = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-android", version.ref = "kotlinxCoroutinesAndroid" }
21 | kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json", version.ref = "kotlinxSerializationJson" }
22 | lifecycle-runtime-ktx = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" }
23 | material = { module = "com.google.android.material:material", version.ref = "material" }
24 | okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
25 |
26 | [plugins]
27 | android-library = { id = "com.android.library", version.ref = "agp" }
28 | jetbrains-kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
29 | jetbrains-kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
30 |
--------------------------------------------------------------------------------
/Example/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 |
4 | def javaVersion = rootProject.ext.javaVersion as JavaVersion
5 |
6 | android {
7 |
8 | namespace 'com.infomaniak.login.example'
9 |
10 | compileSdk 35
11 |
12 | defaultConfig {
13 | applicationId "com.infomaniak.login.example"
14 | minSdkVersion 24
15 | targetSdkVersion 35
16 | versionCode 1
17 | versionName "1.0"
18 |
19 | buildConfigField "String", "APPLICATION_ID_EXEMPLE", '"com.infomaniak.auth"'
20 | buildConfigField "String", "CLIENT_ID_EXEMPLE", '"1d06ddb8-65d7-4e45-a1b1-276f5da71833"'
21 |
22 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
23 | }
24 |
25 | buildTypes {
26 | release {
27 | minifyEnabled false
28 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
29 | }
30 | }
31 |
32 | buildFeatures {
33 | buildConfig = true
34 | }
35 |
36 | compileOptions {
37 | sourceCompatibility javaVersion
38 | targetCompatibility javaVersion
39 | }
40 |
41 | kotlinOptions {
42 | jvmTarget = javaVersion
43 | }
44 |
45 | buildFeatures { viewBinding true }
46 |
47 | }
48 |
49 | dependencies {
50 | implementation fileTree(dir: 'libs', include: ['*.jar'])
51 | implementation project(path: ':Library')
52 |
53 | implementation libs.kotlin.stdlib.jdk8
54 | implementation libs.kotlinx.coroutines.android
55 |
56 | implementation libs.appcompat
57 | implementation libs.constraintlayout
58 | implementation libs.lifecycle.runtime.ktx
59 |
60 | implementation libs.okhttp
61 | }
62 |
--------------------------------------------------------------------------------
/Example/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
15 |
18 |
21 |
22 |
23 |
24 |
30 |
--------------------------------------------------------------------------------
/Example/src/main/res/layout/activity_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
18 |
19 |
27 |
28 |
38 |
39 |
40 |
--------------------------------------------------------------------------------
/Library/src/main/res/layout/activity_web_view_login.xml:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
14 |
15 |
25 |
26 |
32 |
33 |
34 |
35 |
40 |
41 |
42 |
--------------------------------------------------------------------------------
/Library/src/main/java/com/infomaniak/lib/login/ext/OkHttpClientExt.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak Login - Android
3 | * Copyright (C) 2025 Infomaniak Network SA
4 | *
5 | * Licensed under the Apache License, Version 2.0 (the "License");
6 | * you may not use this file except in compliance with the License.
7 | * You may obtain a copy of the License at
8 | *
9 | * http://www.apache.org/licenses/LICENSE-2.0
10 | *
11 | * Unless required by applicable law or agreed to in writing, software
12 | * distributed under the License is distributed on an "AS IS" BASIS,
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 | * See the License for the specific language governing permissions and
15 | * limitations under the License.
16 | */
17 |
18 | package com.infomaniak.lib.login.ext
19 |
20 | import kotlinx.coroutines.suspendCancellableCoroutine
21 | import okhttp3.Call
22 | import okhttp3.Callback
23 | import okhttp3.Response
24 | import okhttp3.internal.closeQuietly
25 | import java.io.IOException
26 | import kotlin.coroutines.resumeWithException
27 |
28 | /**
29 | * Suspend extension that allows suspend [Call.enqueue]
30 | * @return [Response] or throw exception
31 | */
32 | internal suspend fun Call.await() = suspendCancellableCoroutine { continuation ->
33 |
34 | enqueue(object : Callback {
35 | override fun onFailure(call: Call, e: IOException) {
36 | continuation.resumeWithException(e)
37 | }
38 |
39 | override fun onResponse(call: Call, response: Response) {
40 | continuation.resume(response) { _, response, _ ->
41 | response.closeQuietly()
42 | }
43 | }
44 | })
45 |
46 | continuation.invokeOnCancellation {
47 | // We don't need to throw an exception here, it's only reserved for resource releases as the doc says.
48 | // So we make sure that OkHttp doesn't throw us an exception when we cancel it.
49 | runCatching { this@await.cancel() }
50 | }
51 | }
52 |
--------------------------------------------------------------------------------
/Library/build.gradle:
--------------------------------------------------------------------------------
1 | plugins {
2 | alias(libs.plugins.android.library)
3 | alias(libs.plugins.jetbrains.kotlin.android)
4 | alias(libs.plugins.jetbrains.kotlin.serialization)
5 | id 'kotlin-parcelize'
6 | id 'maven-publish'
7 | }
8 |
9 | group = 'com.github.Infomaniak'
10 |
11 | android {
12 |
13 | namespace 'com.infomaniak.lib.login'
14 |
15 | compileSdk 35
16 |
17 | defaultConfig {
18 | minSdkVersion 24
19 | targetSdkVersion 35
20 |
21 | testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
22 | }
23 |
24 | buildTypes {
25 | release {
26 | minifyEnabled false
27 | proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
28 | }
29 | }
30 |
31 | publishing {
32 | singleVariant("release") {
33 | withSourcesJar()
34 | }
35 | }
36 |
37 | compileOptions {
38 | sourceCompatibility rootProject.ext.javaVersion
39 | targetCompatibility rootProject.ext.javaVersion
40 | }
41 |
42 | kotlinOptions {
43 | jvmTarget = rootProject.ext.javaVersion
44 | }
45 |
46 | buildFeatures { viewBinding true }
47 |
48 | }
49 |
50 | dependencies {
51 | implementation fileTree(dir: 'libs', include: ['*.jar'])
52 | implementation libs.kotlin.stdlib.jdk8
53 | implementation libs.kotlinx.coroutines.android
54 |
55 | implementation libs.browser
56 | implementation libs.appcompat
57 |
58 | implementation libs.gson
59 | implementation libs.kotlinx.serialization.json
60 | implementation libs.material
61 |
62 | implementation libs.okhttp
63 | }
64 |
65 | afterEvaluate {
66 | publishing {
67 | publications {
68 | release(MavenPublication) {
69 | from components.findByName('release')
70 | groupId = 'com.github.infomaniak'
71 | artifactId = 'android-login'
72 | version = "3.1.10"
73 | }
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/Example/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
23 |
24 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
48 |
49 |
52 |
53 |
54 |
55 |
56 |
--------------------------------------------------------------------------------
/Example/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
19 |
20 |
29 |
30 |
39 |
40 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/Library/src/main/java/com/infomaniak/lib/login/WebViewLoginActivity.kt:
--------------------------------------------------------------------------------
1 | package com.infomaniak.lib.login
2 |
3 | import android.annotation.SuppressLint
4 | import android.os.Bundle
5 | import android.view.Menu
6 | import android.view.MenuItem
7 | import androidx.activity.enableEdgeToEdge
8 | import androidx.appcompat.app.AppCompatActivity
9 | import com.infomaniak.lib.login.InfomaniakLogin.Companion.LOGIN_URL_TAG
10 | import com.infomaniak.lib.login.InfomaniakLogin.Companion.REMOVE_COOKIES_TAG
11 | import com.infomaniak.lib.login.databinding.ActivityWebViewLoginBinding
12 | import com.infomaniak.lib.login.ext.handleEdgeToEdge
13 | import java.util.MissingFormatArgumentException
14 |
15 | class WebViewLoginActivity : AppCompatActivity() {
16 |
17 | private val binding by lazy { ActivityWebViewLoginBinding.inflate(layoutInflater) }
18 |
19 | private val appUID: String by lazy {
20 | intent.getStringExtra(APPLICATION_ID_TAG) ?: throw MissingFormatArgumentException(APPLICATION_ID_TAG)
21 | }
22 | private val loginUrl: String by lazy {
23 | intent.getStringExtra(LOGIN_URL_TAG) ?: throw MissingFormatArgumentException(LOGIN_URL_TAG)
24 | }
25 | private val removeCookies: Boolean by lazy {
26 | intent.getBooleanExtra(REMOVE_COOKIES_TAG, true)
27 | }
28 |
29 | @SuppressLint("SetJavaScriptEnabled")
30 | override fun onCreate(savedInstanceState: Bundle?) {
31 | super.onCreate(savedInstanceState)
32 | setContentView(binding.root)
33 | setSupportActionBar(binding.toolbar)
34 |
35 | enableEdgeToEdge()
36 |
37 | if (removeCookies) WebViewUtils.flushAllCookies()
38 | binding.handleEdgeToEdge()
39 |
40 | binding.webview.apply {
41 | settings.javaScriptEnabled = true
42 | webViewClient = LoginWebViewClient(
43 | activity = this@WebViewLoginActivity,
44 | progressBar = binding.progressBar,
45 | appUID = appUID,
46 | baseUrl = loginUrl,
47 | )
48 | webChromeClient = ProgressWebChromeClient(binding.progressBar)
49 | loadUrl(loginUrl)
50 | }
51 | }
52 |
53 | override fun onCreateOptionsMenu(menu: Menu?): Boolean {
54 | menuInflater.inflate(R.menu.webview_menu, menu)
55 | return true
56 | }
57 |
58 | override fun onOptionsItemSelected(item: MenuItem): Boolean {
59 | return when (item.itemId) {
60 | R.id.doneItem -> {
61 | finish()
62 | true
63 | }
64 |
65 | else -> false
66 | }
67 | }
68 |
69 | companion object {
70 |
71 | const val APPLICATION_ID_TAG = "appUID"
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/Example/src/main/java/com/infomaniak/login/example/FragmentMainFragment.kt:
--------------------------------------------------------------------------------
1 | package com.infomaniak.login.example
2 |
3 | import android.content.Intent
4 | import android.os.Bundle
5 | import android.util.Log
6 | import android.view.LayoutInflater
7 | import android.view.View
8 | import android.view.ViewGroup
9 | import android.widget.Toast
10 | import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
11 | import androidx.appcompat.app.AppCompatActivity
12 | import androidx.fragment.app.Fragment
13 | import com.infomaniak.lib.login.InfomaniakLogin
14 | import com.infomaniak.login.example.BuildConfig.APPLICATION_ID_EXEMPLE
15 | import com.infomaniak.login.example.BuildConfig.CLIENT_ID_EXEMPLE
16 | import com.infomaniak.login.example.databinding.FragmentMainBinding
17 |
18 | class FragmentMainFragment : Fragment() {
19 |
20 | private lateinit var binding: FragmentMainBinding
21 |
22 | companion object {
23 | fun newInstance() = FragmentMainFragment()
24 | }
25 |
26 | private lateinit var infomaniakLogin: InfomaniakLogin
27 |
28 |
29 | override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
30 | return FragmentMainBinding.inflate(inflater, container, false).also { binding = it }.root
31 | }
32 |
33 | override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
34 | super.onViewCreated(view, savedInstanceState)
35 |
36 | infomaniakLogin = InfomaniakLogin(
37 | context = requireContext(),
38 | clientID = CLIENT_ID_EXEMPLE,
39 | appUID = APPLICATION_ID_EXEMPLE,
40 | )
41 |
42 | binding.webViewLoginButton.setOnClickListener { infomaniakLogin.startWebViewLogin(webViewLoginResultLauncher) }
43 | }
44 |
45 | private val webViewLoginResultLauncher = registerForActivityResult(StartActivityForResult()) { result ->
46 | with(result) {
47 | if (resultCode == AppCompatActivity.RESULT_OK) {
48 | val code = data?.extras?.getString(InfomaniakLogin.CODE_TAG)
49 |
50 | if (!code.isNullOrBlank()) {
51 | Log.d("WebView code", code)
52 | val intent = Intent(requireContext(), LoginActivity::class.java).apply {
53 | putExtra("code", code)
54 | }
55 | startActivity(intent)
56 | } else {
57 | val errorCode = data?.extras?.getString(InfomaniakLogin.ERROR_CODE_TAG)
58 | val translatedError = data?.extras?.getString(InfomaniakLogin.ERROR_TRANSLATED_TAG)
59 |
60 | Toast.makeText(requireContext(), translatedError, Toast.LENGTH_LONG).show()
61 | Log.d("WebView error", errorCode ?: "")
62 | }
63 | }
64 | }
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/Example/src/main/java/com/infomaniak/login/example/LoginActivity.kt:
--------------------------------------------------------------------------------
1 | package com.infomaniak.login.example
2 |
3 | import android.os.Bundle
4 | import androidx.appcompat.app.AppCompatActivity
5 | import androidx.core.view.isVisible
6 | import androidx.lifecycle.lifecycleScope
7 | import com.infomaniak.lib.login.ApiToken
8 | import com.infomaniak.lib.login.InfomaniakLogin
9 | import com.infomaniak.login.example.BuildConfig.APPLICATION_ID_EXEMPLE
10 | import com.infomaniak.login.example.BuildConfig.CLIENT_ID_EXEMPLE
11 | import com.infomaniak.login.example.databinding.ActivityLoginBinding
12 | import kotlinx.coroutines.launch
13 | import okhttp3.OkHttpClient
14 |
15 | class LoginActivity : AppCompatActivity() {
16 |
17 | private val binding: ActivityLoginBinding by lazy { ActivityLoginBinding.inflate(layoutInflater) }
18 |
19 | override fun onCreate(savedInstanceState: Bundle?) = with(binding) {
20 | super.onCreate(savedInstanceState)
21 | setContentView(root)
22 |
23 | if (intent != null) {
24 | intent.getStringExtra("code")?.let {
25 | val infomaniakLogin = InfomaniakLogin(
26 | context = this@LoginActivity,
27 | clientID = CLIENT_ID_EXEMPLE,
28 | appUID = APPLICATION_ID_EXEMPLE,
29 | )
30 |
31 | lifecycleScope.launch {
32 | val okHttpClient = OkHttpClient.Builder().build()
33 |
34 | val tokenResult = infomaniakLogin.getToken(okHttpClient, code = it)
35 | updateUi(tokenResult, infomaniakLogin, okHttpClient)
36 | }
37 | }
38 | }
39 | }
40 |
41 | private fun ActivityLoginBinding.updateUi(
42 | tokenResult: InfomaniakLogin.TokenResult,
43 | infomaniakLogin: InfomaniakLogin,
44 | okHttpClient: OkHttpClient,
45 | ) {
46 | when (tokenResult) {
47 | is InfomaniakLogin.TokenResult.Success -> {
48 | val apiToken = tokenResult.apiToken
49 | getTokenStatus.text = "${apiToken.userId} ${apiToken.accessToken}"
50 |
51 | btnLogout.apply {
52 | isVisible = true
53 | setOnClickListener { infomaniakLogin.logout(okHttpClient, apiToken) }
54 | }
55 | }
56 |
57 | is InfomaniakLogin.TokenResult.Error -> when (tokenResult.errorStatus) {
58 | InfomaniakLogin.ErrorStatus.SERVER -> getTokenStatus.text = "Server error"
59 | else -> getTokenStatus.text = "Error"
60 | }
61 | }
62 | }
63 |
64 | private fun InfomaniakLogin.logout(okHttpClient: OkHttpClient, token: ApiToken) = with(binding) {
65 | lifecycleScope.launch {
66 | when (val errorStatus = deleteToken(okHttpClient, token)) {
67 | null -> deleteTokenStatus.text = "Delete token success"
68 | else -> deleteTokenStatus.text = "Error in token deletion : ${errorStatus.name}"
69 | }
70 | }
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
33 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
34 |
35 | @rem Find java.exe
36 | if defined JAVA_HOME goto findJavaFromJavaHome
37 |
38 | set JAVA_EXE=java.exe
39 | %JAVA_EXE% -version >NUL 2>&1
40 | if "%ERRORLEVEL%" == "0" goto init
41 |
42 | echo.
43 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
44 | echo.
45 | echo Please set the JAVA_HOME variable in your environment to match the
46 | echo location of your Java installation.
47 |
48 | goto fail
49 |
50 | :findJavaFromJavaHome
51 | set JAVA_HOME=%JAVA_HOME:"=%
52 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
53 |
54 | if exist "%JAVA_EXE%" goto init
55 |
56 | echo.
57 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
58 | echo.
59 | echo Please set the JAVA_HOME variable in your environment to match the
60 | echo location of your Java installation.
61 |
62 | goto fail
63 |
64 | :init
65 | @rem Get command-line arguments, handling Windows variants
66 |
67 | if not "%OS%" == "Windows_NT" goto win9xME_args
68 |
69 | :win9xME_args
70 | @rem Slurp the command line arguments.
71 | set CMD_LINE_ARGS=
72 | set _SKIP=2
73 |
74 | :win9xME_args_slurp
75 | if "x%~1" == "x" goto execute
76 |
77 | set CMD_LINE_ARGS=%*
78 |
79 | :execute
80 | @rem Setup the command line
81 |
82 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
83 |
84 | @rem Execute Gradle
85 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
86 |
87 | :end
88 | @rem End local scope for the variables with windows NT shell
89 | if "%ERRORLEVEL%"=="0" goto mainEnd
90 |
91 | :fail
92 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
93 | rem the _cmd.exe /c_ return code!
94 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
95 | exit /b 1
96 |
97 | :mainEnd
98 | if "%OS%"=="Windows_NT" endlocal
99 |
100 | :omega
101 |
--------------------------------------------------------------------------------
/Example/src/main/java/com/infomaniak/login/example/MainActivity.kt:
--------------------------------------------------------------------------------
1 | package com.infomaniak.login.example
2 |
3 | import android.content.Intent
4 | import android.os.Bundle
5 | import android.util.Log
6 | import android.widget.Toast
7 | import androidx.activity.result.contract.ActivityResultContracts.StartActivityForResult
8 | import androidx.appcompat.app.AppCompatActivity
9 | import com.infomaniak.lib.login.InfomaniakLogin
10 | import com.infomaniak.login.example.BuildConfig.APPLICATION_ID_EXEMPLE
11 | import com.infomaniak.login.example.BuildConfig.CLIENT_ID_EXEMPLE
12 | import com.infomaniak.login.example.databinding.ActivityMainBinding
13 |
14 | class MainActivity : AppCompatActivity() {
15 |
16 | private val binding: ActivityMainBinding by lazy { ActivityMainBinding.inflate(layoutInflater) }
17 |
18 | private lateinit var infomaniakLogin: InfomaniakLogin
19 |
20 | private val createAccountResultLauncher = registerForActivityResult(StartActivityForResult()) { result ->
21 | if (result.resultCode == RESULT_OK) {
22 | val codeError = result.data?.getStringExtra(InfomaniakLogin.ERROR_CODE_TAG)
23 | val translatedError = result.data?.getStringExtra(InfomaniakLogin.ERROR_TRANSLATED_TAG)
24 | if (translatedError.isNullOrBlank()) {
25 | Toast.makeText(this@MainActivity, "Creation ok", Toast.LENGTH_LONG).show()
26 | } else {
27 | Toast.makeText(this@MainActivity, "$codeError: $translatedError", Toast.LENGTH_LONG).show()
28 | }
29 | }
30 | }
31 |
32 | override fun onCreate(savedInstanceState: Bundle?) = with(binding) {
33 | super.onCreate(savedInstanceState)
34 | setContentView(root)
35 |
36 | infomaniakLogin = InfomaniakLogin(
37 | context = this@MainActivity,
38 | clientID = CLIENT_ID_EXEMPLE,
39 | appUID = APPLICATION_ID_EXEMPLE,
40 | )
41 |
42 | infomaniakLogin.checkResponse(
43 | intent = intent,
44 | onSuccess = { code ->
45 | val intent = Intent(this@MainActivity, LoginActivity::class.java).apply {
46 | putExtra("code", code)
47 | }
48 | startActivity(intent)
49 | },
50 | onError = { error -> Toast.makeText(this@MainActivity, error, Toast.LENGTH_LONG).show() },
51 | )
52 |
53 | loginButton.setOnClickListener { infomaniakLogin.start() }
54 |
55 | webViewLoginButton.setOnClickListener { infomaniakLogin.startWebViewLogin(webViewLoginResultLauncher) }
56 |
57 | fragmentLoginButton.setOnClickListener { startActivity(Intent(this@MainActivity, FragmentMainActivity::class.java)) }
58 |
59 | createAccountButton.setOnClickListener {
60 | infomaniakLogin.startCreateAccountWebView(
61 | resultLauncher = createAccountResultLauncher,
62 | createAccountUrl = "https://welcome.infomaniak.com/signup/ikmail?app=true",
63 | successHost = "ksuite.infomaniak.com", // Before it was mail.infomaniak.com
64 | cancelHost = "welcome.infomaniak.com",
65 | )
66 | }
67 | }
68 |
69 | private val webViewLoginResultLauncher = registerForActivityResult(StartActivityForResult()) { result ->
70 | with(result) {
71 | if (resultCode == RESULT_OK) {
72 | val code = data?.extras?.getString(InfomaniakLogin.CODE_TAG)
73 |
74 | if (!code.isNullOrBlank()) {
75 | Log.d("WebView code", code)
76 | val intent = Intent(this@MainActivity, LoginActivity::class.java).apply {
77 | putExtra("code", code)
78 | }
79 | startActivity(intent)
80 | } else {
81 | val errorCode = data?.extras?.getString(InfomaniakLogin.ERROR_CODE_TAG)
82 | val translatedError = data?.extras?.getString(InfomaniakLogin.ERROR_TRANSLATED_TAG)
83 |
84 | Toast.makeText(this@MainActivity, translatedError, Toast.LENGTH_LONG).show()
85 | Log.d("WebView error", errorCode ?: "")
86 | }
87 | }
88 | }
89 | }
90 |
91 | public override fun onDestroy() {
92 | infomaniakLogin.unbind()
93 | super.onDestroy()
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/.idea/codeStyles/Project.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 | xmlns:android
27 |
28 | ^$
29 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 | xmlns:.*
38 |
39 | ^$
40 |
41 |
42 | BY_NAME
43 |
44 |
45 |
46 |
47 |
48 |
49 | .*:id
50 |
51 | http://schemas.android.com/apk/res/android
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 | .*:name
61 |
62 | http://schemas.android.com/apk/res/android
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 | name
72 |
73 | ^$
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 | style
83 |
84 | ^$
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 | .*
94 |
95 | ^$
96 |
97 |
98 | BY_NAME
99 |
100 |
101 |
102 |
103 |
104 |
105 | .*
106 |
107 | http://schemas.android.com/apk/res/android
108 |
109 |
110 | ANDROID_ATTRIBUTE_ORDER
111 |
112 |
113 |
114 |
115 |
116 |
117 | .*
118 |
119 | .*
120 |
121 |
122 | BY_NAME
123 |
124 |
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Infomaniak Login Library
2 |
3 | Library to simplify login process with Infomaniak oauth 2.0 protocol
4 |
5 | ## Install
6 |
7 | In the `build.gradle` of your lib/app (not root level), add this instruction :
8 |
9 | ```groovy
10 | implementation 'com.github.Infomaniak:android-login:3.0.0'
11 | ```
12 |
13 | ## Use Login
14 |
15 | In the `onCreate` method of your Activity/Fragment, instantiate the library :
16 |
17 | ```kotlin
18 | val loginInstance = InfomaniakLogin(
19 | context = this,
20 | clientId = CLIENT_ID,
21 | redirectUri = "$APP_UID:/oauth2redirect"
22 | )
23 | ```
24 |
25 | with these arguments :
26 |
27 | - `context` : The current activity/fragment context (will be used to show a Chrometab)
28 | - `clientId` : The client ID of the app
29 | - `redirectUri` : The redirection URL after a successful login (in order to handle the codes)
30 |
31 | **Once instantiated, you may use this everywhere in your activity/fragment, for example in a `onClick` method :**
32 |
33 | ```kotlin
34 | buttonConnect.setOnClickListener {
35 | loginInstance.start()
36 | }
37 | ```
38 |
39 | It will create a custom chrome tab or launch the browser.
40 | If needed (to see if an error occurred), the `start()` method returns a boolean indicating the success (or not) of the operation.
41 |
42 | **Or you can use the `loginInstance` to create a login from a webview.**
43 |
44 | ```kotlin
45 | buttonConnect.setOnClickListener {
46 | infomaniakLogin.startWebViewLogin(/*resultLauncher: ActivityResultLauncher*/)
47 | }
48 | ```
49 |
50 | It will create an activity that contains a WebView. The `startWebViewLogin` takes as parameter a resultLauncher to handle the
51 | activity results.
52 |
53 | ```kotlin
54 | private val webViewLoginResultLauncher = registerForActivityResult(StartActivityForResult()) { result ->
55 | with(result) {
56 | if (resultCode == RESULT_OK) {
57 | val authCode = data?.getStringExtra(InfomaniakLogin.CODE_TAG)
58 | val translatedError = data?.getStringExtra(InfomaniakLogin.ERROR_TRANSLATED_TAG)
59 | when {
60 | translatedError?.isNotBlank() == true -> showError(translatedError)
61 | authCode?.isNotBlank() == true -> authenticateUser(authCode)
62 | else -> showError(getString(RCore.string.anErrorHasOccurred))
63 | }
64 | }
65 | }
66 | }
67 | ```
68 |
69 | This allows you to retrieve the answers from the WebView, either the `code` for `auth` in case of success, or in case of error, we
70 | retrieve the `error code` and the `translated error message`.
71 |
72 | Add this to the manifest, to authorize the WebView :
73 |
74 | ```xml
75 |
76 |
77 | ```
78 |
79 | ## Use Create account
80 |
81 | **From your `loginInstance`, you need to call the method `startCreateAccountWebView`**
82 |
83 | ```kotlin
84 | infomaniakLogin.startCreateAccountWebView(
85 | resultLauncher = createAccountResultLauncher,
86 | createAccountUrl = BuildConfig.CREATE_ACCOUNT_URL,
87 | successHost = BuildConfig.CREATE_ACCOUNT_SUCCESS_HOST,
88 | cancelHost = BuildConfig.CREATE_ACCOUNT_CANCEL_HOST,
89 | )
90 | ```
91 |
92 | with these arguments :
93 |
94 | - `resultLauncher` : Send back the result, it's an `ActivityResultLauncher`
95 | - `createAccountUrl` : The url of the account creation page
96 | - `successHost` : The host name when the account creation was successful
97 | - `cancelHost` : The host name to connect, cancel will be invoke
98 |
99 | **Create your `resultLauncher` to handle the `activity results`**
100 |
101 | ```kotlin
102 | private val createAccountResultLauncher = registerForActivityResult(StartActivityForResult()) { result ->
103 | if (result.resultCode == RESULT_OK) {
104 | val translatedError = result.data?.getStringExtra(InfomaniakLogin.ERROR_TRANSLATED_TAG)
105 | when {
106 | translatedError.isNullOrBlank() -> infomaniakLogin.startWebViewLogin(webViewLoginResultLauncher, false)
107 | else -> showError(translatedError)
108 | }
109 | }
110 | }
111 | ```
112 |
113 | **Finally, you need to add `WebViewLoginActivity` to the manifest**
114 |
115 | ```xml
116 |
117 |
118 | ```
119 |
120 | ## License
121 |
122 | Copyright 2021 Infomaniak
123 |
124 | Licensed under the Apache License, Version 2.0 (the "License");
125 | you may not use this file except in compliance with the License.
126 | You may obtain a copy of the License at
127 |
128 | http://www.apache.org/licenses/LICENSE-2.0
129 |
130 | Unless required by applicable law or agreed to in writing, software
131 | distributed under the License is distributed on an "AS IS" BASIS,
132 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133 | See the License for the specific language governing permissions and
134 | limitations under the License.
135 |
--------------------------------------------------------------------------------
/Library/src/main/java/com/infomaniak/lib/login/WebViewCreateAccountActivity.kt:
--------------------------------------------------------------------------------
1 | /*
2 | * Infomaniak kMail - Android
3 | * Copyright (C) 2023 Infomaniak Network SA
4 | *
5 | * This program is free software: you can redistribute it and/or modify
6 | * it under the terms of the GNU General Public License as published by
7 | * the Free Software Foundation, either version 3 of the License, or
8 | * (at your option) any later version.
9 | *
10 | * This program is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU General Public License
16 | * along with this program. If not, see .
17 | */
18 | package com.infomaniak.lib.login
19 |
20 | import android.annotation.SuppressLint
21 | import android.app.Activity
22 | import android.content.Intent
23 | import android.os.Bundle
24 | import android.view.Menu
25 | import android.view.MenuItem
26 | import android.webkit.WebResourceError
27 | import android.webkit.WebResourceRequest
28 | import android.webkit.WebView
29 | import android.widget.ProgressBar
30 | import androidx.appcompat.app.AppCompatActivity
31 | import androidx.core.net.toUri
32 | import com.infomaniak.lib.login.InfomaniakLogin.Companion.CANCEL_HOST_TAG
33 | import com.infomaniak.lib.login.InfomaniakLogin.Companion.CREATE_ACCOUNT_URL_TAG
34 | import com.infomaniak.lib.login.InfomaniakLogin.Companion.HEADERS_TAG
35 | import com.infomaniak.lib.login.InfomaniakLogin.Companion.IGNORE_FIRST_CANCEL_URL_TAG
36 | import com.infomaniak.lib.login.InfomaniakLogin.Companion.REMOVE_COOKIES_TAG
37 | import com.infomaniak.lib.login.InfomaniakLogin.Companion.SUCCESS_HOST_TAG
38 | import com.infomaniak.lib.login.databinding.ActivityWebViewLoginBinding
39 | import com.infomaniak.lib.login.ext.handleEdgeToEdge
40 | import kotlinx.serialization.json.Json
41 | import java.util.MissingFormatArgumentException
42 |
43 | class WebViewCreateAccountActivity : AppCompatActivity() {
44 |
45 | private val binding by lazy { ActivityWebViewLoginBinding.inflate(layoutInflater) }
46 |
47 | private val createAccountUrl: String by lazy {
48 | intent.getStringExtra(CREATE_ACCOUNT_URL_TAG) ?: throw MissingFormatArgumentException(CREATE_ACCOUNT_URL_TAG)
49 | }
50 | private val successUrl: String by lazy {
51 | intent.getStringExtra(SUCCESS_HOST_TAG) ?: throw MissingFormatArgumentException(SUCCESS_HOST_TAG)
52 | }
53 | private val cancelUrl: String by lazy {
54 | intent.getStringExtra(CANCEL_HOST_TAG) ?: throw MissingFormatArgumentException(CANCEL_HOST_TAG)
55 | }
56 | private val removeCookies: Boolean by lazy {
57 | intent.getBooleanExtra(REMOVE_COOKIES_TAG, true)
58 | }
59 | private val headers: Map by lazy {
60 | intent.getStringExtra(HEADERS_TAG)?.let {
61 | Json.decodeFromString