Skip to content

Instantly share code, notes, and snippets.

@johnkil
Created May 6, 2023 13:28
Show Gist options
  • Save johnkil/3548737f1eb00573a4d0838653e2a5b1 to your computer and use it in GitHub Desktop.
Save johnkil/3548737f1eb00573a4d0838653e2a5b1 to your computer and use it in GitHub Desktop.
@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