Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unlimited token #118

Merged
merged 2 commits into from
Jan 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ dependencies {
api "io.coil-kt:coil-gif:$coilVersion"
api "io.coil-kt:coil:$coilVersion"

api "com.github.Infomaniak:android-login:2.7.2"
api "com.github.Infomaniak:android-login:2.8.0"
api 'com.facebook.stetho:stetho-okhttp3:1.6.0'
api 'com.squareup.okhttp3:okhttp:4.12.0'
api 'io.sentry:sentry-android:7.1.0'
Expand Down
339 changes: 339 additions & 0 deletions schemas/com.infomaniak.lib.core.room.UserDatabase/5.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,339 @@
{
"formatVersion": 1,
"database": {
"version": 5,
"identityHash": "6f81046652c11273fb7c02125367198c",
"entities": [
{
"tableName": "User",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `displayName` TEXT, `firstname` TEXT NOT NULL, `lastname` TEXT NOT NULL, `email` TEXT NOT NULL, `avatar` TEXT, `login` TEXT NOT NULL, `isStaff` INTEGER NOT NULL DEFAULT false, `phones` TEXT, `emails` TEXT, `organizations` TEXT NOT NULL, `preferences_security_score` INTEGER DEFAULT 0, `preferences_security_hasRecoveryEmail` INTEGER DEFAULT false, `preferences_security_hasValidPhone` INTEGER DEFAULT false, `preferences_security_emailValidatedAt` INTEGER DEFAULT 0, `preferences_security_otp` INTEGER DEFAULT false, `preferences_security_sms` INTEGER DEFAULT false, `preferences_security_smsPhone` TEXT DEFAULT '', `preferences_security_yubikey` INTEGER DEFAULT false, `preferences_security_infomaniakApplication` INTEGER DEFAULT false, `preferences_security_doubleAuth` INTEGER DEFAULT false, `preferences_security_remainingRescueCode` INTEGER DEFAULT 0, `preferences_security_lastLoginAt` INTEGER DEFAULT 0, `preferences_security_dateLastChangedPassword` INTEGER DEFAULT 0, `preferences_security_doubleAuthMethod` TEXT DEFAULT '', `preferences_security_authDevices` TEXT, `preferences_organizationPreference_currentOrganizationId` INTEGER NOT NULL DEFAULT 0, `preferences_organizationPreference_lastLoginAt` INTEGER NOT NULL DEFAULT 0, `preferences_language_shortName` TEXT NOT NULL DEFAULT '', `preferences_language_locale` TEXT NOT NULL DEFAULT '', `preferences_language_shortLocale` TEXT NOT NULL DEFAULT '', `preferences_language_id` INTEGER NOT NULL DEFAULT 0, `preferences_language_name` TEXT NOT NULL DEFAULT '', `preferences_country_shortName` TEXT NOT NULL DEFAULT '', `preferences_country_isEnabled` INTEGER NOT NULL DEFAULT false, `preferences_country_id` INTEGER NOT NULL DEFAULT 0, `preferences_country_name` TEXT NOT NULL DEFAULT '', `preferences_timezone_gmt` TEXT DEFAULT '', `preferences_timezone_id` INTEGER DEFAULT 0, `preferences_timezone_name` TEXT DEFAULT '', `accessToken` TEXT NOT NULL, `refreshToken` TEXT, `tokenType` TEXT NOT NULL, `expiresIn` INTEGER NOT NULL, `userId` INTEGER NOT NULL, `scope` TEXT, `expiresAt` INTEGER, PRIMARY KEY(`id`))",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "displayName",
"columnName": "displayName",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "firstname",
"columnName": "firstname",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "lastname",
"columnName": "lastname",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "email",
"columnName": "email",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "avatar",
"columnName": "avatar",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "login",
"columnName": "login",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "isStaff",
"columnName": "isStaff",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "false"
},
{
"fieldPath": "phones",
"columnName": "phones",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "emails",
"columnName": "emails",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "organizations",
"columnName": "organizations",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "preferences.security.score",
"columnName": "preferences_security_score",
"affinity": "INTEGER",
"notNull": false,
"defaultValue": "0"
},
{
"fieldPath": "preferences.security.hasRecoveryEmail",
"columnName": "preferences_security_hasRecoveryEmail",
"affinity": "INTEGER",
"notNull": false,
"defaultValue": "false"
},
{
"fieldPath": "preferences.security.hasValidPhone",
"columnName": "preferences_security_hasValidPhone",
"affinity": "INTEGER",
"notNull": false,
"defaultValue": "false"
},
{
"fieldPath": "preferences.security.emailValidatedAt",
"columnName": "preferences_security_emailValidatedAt",
"affinity": "INTEGER",
"notNull": false,
"defaultValue": "0"
},
{
"fieldPath": "preferences.security.otp",
"columnName": "preferences_security_otp",
"affinity": "INTEGER",
"notNull": false,
"defaultValue": "false"
},
{
"fieldPath": "preferences.security.sms",
"columnName": "preferences_security_sms",
"affinity": "INTEGER",
"notNull": false,
"defaultValue": "false"
},
{
"fieldPath": "preferences.security.smsPhone",
"columnName": "preferences_security_smsPhone",
"affinity": "TEXT",
"notNull": false,
"defaultValue": "''"
},
{
"fieldPath": "preferences.security.yubikey",
"columnName": "preferences_security_yubikey",
"affinity": "INTEGER",
"notNull": false,
"defaultValue": "false"
},
{
"fieldPath": "preferences.security.infomaniakApplication",
"columnName": "preferences_security_infomaniakApplication",
"affinity": "INTEGER",
"notNull": false,
"defaultValue": "false"
},
{
"fieldPath": "preferences.security.doubleAuth",
"columnName": "preferences_security_doubleAuth",
"affinity": "INTEGER",
"notNull": false,
"defaultValue": "false"
},
{
"fieldPath": "preferences.security.remainingRescueCode",
"columnName": "preferences_security_remainingRescueCode",
"affinity": "INTEGER",
"notNull": false,
"defaultValue": "0"
},
{
"fieldPath": "preferences.security.lastLoginAt",
"columnName": "preferences_security_lastLoginAt",
"affinity": "INTEGER",
"notNull": false,
"defaultValue": "0"
},
{
"fieldPath": "preferences.security.dateLastChangedPassword",
"columnName": "preferences_security_dateLastChangedPassword",
"affinity": "INTEGER",
"notNull": false,
"defaultValue": "0"
},
{
"fieldPath": "preferences.security.doubleAuthMethod",
"columnName": "preferences_security_doubleAuthMethod",
"affinity": "TEXT",
"notNull": false,
"defaultValue": "''"
},
{
"fieldPath": "preferences.security.authDevices",
"columnName": "preferences_security_authDevices",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "preferences.organizationPreference.currentOrganizationId",
"columnName": "preferences_organizationPreference_currentOrganizationId",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "preferences.organizationPreference.lastLoginAt",
"columnName": "preferences_organizationPreference_lastLoginAt",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "preferences.language.shortName",
"columnName": "preferences_language_shortName",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "''"
},
{
"fieldPath": "preferences.language.locale",
"columnName": "preferences_language_locale",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "''"
},
{
"fieldPath": "preferences.language.shortLocale",
"columnName": "preferences_language_shortLocale",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "''"
},
{
"fieldPath": "preferences.language.id",
"columnName": "preferences_language_id",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "preferences.language.name",
"columnName": "preferences_language_name",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "''"
},
{
"fieldPath": "preferences.country.shortName",
"columnName": "preferences_country_shortName",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "''"
},
{
"fieldPath": "preferences.country.isEnabled",
"columnName": "preferences_country_isEnabled",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "false"
},
{
"fieldPath": "preferences.country.id",
"columnName": "preferences_country_id",
"affinity": "INTEGER",
"notNull": true,
"defaultValue": "0"
},
{
"fieldPath": "preferences.country.name",
"columnName": "preferences_country_name",
"affinity": "TEXT",
"notNull": true,
"defaultValue": "''"
},
{
"fieldPath": "preferences.timezone.gmt",
"columnName": "preferences_timezone_gmt",
"affinity": "TEXT",
"notNull": false,
"defaultValue": "''"
},
{
"fieldPath": "preferences.timezone.id",
"columnName": "preferences_timezone_id",
"affinity": "INTEGER",
"notNull": false,
"defaultValue": "0"
},
{
"fieldPath": "preferences.timezone.name",
"columnName": "preferences_timezone_name",
"affinity": "TEXT",
"notNull": false,
"defaultValue": "''"
},
{
"fieldPath": "apiToken.accessToken",
"columnName": "accessToken",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "apiToken.refreshToken",
"columnName": "refreshToken",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "apiToken.tokenType",
"columnName": "tokenType",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "apiToken.expiresIn",
"columnName": "expiresIn",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "apiToken.userId",
"columnName": "userId",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "apiToken.scope",
"columnName": "scope",
"affinity": "TEXT",
"notNull": false
},
{
"fieldPath": "apiToken.expiresAt",
"columnName": "expiresAt",
"affinity": "INTEGER",
"notNull": false
}
],
"primaryKey": {
"autoGenerate": false,
"columnNames": [
"id"
]
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '6f81046652c11273fb7c02125367198c')"
]
}
}
2 changes: 2 additions & 0 deletions src/main/java/com/infomaniak/lib/core/InfomaniakCore.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package com.infomaniak.lib.core

import com.infomaniak.lib.core.auth.CredentialManager
import com.infomaniak.lib.core.utils.ApiErrorCode
import com.infomaniak.lib.login.InfomaniakLogin.AccessType

/**
* InfomaniakCore : Allow to instantiate the library with some parameters
Expand All @@ -33,6 +34,7 @@ object InfomaniakCore {
var credentialManager: CredentialManager? = null
var customHeaders: MutableMap<String, String>? = null
var apiErrorCodes: List<ApiErrorCode>? = null
var accessType: AccessType? = AccessType.OFFLINE

fun init(
appId: String,
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/com/infomaniak/lib/core/api/ApiController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -94,13 +94,21 @@ object ApiController {
return toJson.toRequestBody(jsonMediaType)
}

suspend fun refreshToken(refreshToken: String, tokenInterceptorListener: TokenInterceptorListener): ApiToken {
suspend fun refreshToken(refreshToken: String?, tokenInterceptorListener: TokenInterceptorListener): ApiToken {

if (refreshToken.isNullOrBlank()) {
tokenInterceptorListener.onRefreshTokenError()
throw RefreshTokenException()
}

val formBuilder: MultipartBody.Builder = MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("grant_type", "refresh_token")
.addFormDataPart("client_id", InfomaniakCore.clientId)
.addFormDataPart("refresh_token", refreshToken)

if (InfomaniakCore.accessType == null) formBuilder.addFormDataPart("duration", "infinite")

return withContext(Dispatchers.IO) {
val request = Request.Builder()
.url("${LOGIN_ENDPOINT_URL}token")
Expand Down
Loading