Created
May 6, 2023 13:28
-
-
Save johnkil/3548737f1eb00573a4d0838653e2a5b1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Singleton | |
class OAuthTokenLocalDataSource @Inject constructor( | |
app: Application | |
) { | |
private val sharedPrefs: SharedPreferences = EncryptedSharedPreferences.create( | |
"oauth_token_local_data_source", | |
MasterKeys.getOrCreate(MasterKeys.AES256_GCM_SPEC), | |
app, | |
EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, | |
EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM | |
) | |
var oAuthToken: OAuthToken? | |
get() = sharedPrefs.getString(KEY_OAUTH_TOKEN, null)?.let(Json::decodeFromString) | |
set(value) { | |
sharedPrefs.edit { | |
putString(KEY_OAUTH_TOKEN, value?.let(Json::encodeToString)) | |
} | |
} | |
private companion object { | |
private const val KEY_OAUTH_TOKEN = "oauth_token" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment