-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backed out API implementation changes (#15)
* Backed out API implementation changes. A lot of the internals of the implementation are relied on by the Tracking SDK, so they can't be removed at this time. * Moved context to last parameter. This will make it easier to deprecate the parameter in the future. * Fixed another context parameter and README
- Loading branch information
1 parent
29656c5
commit 4c6abff
Showing
17 changed files
with
1,270 additions
and
395 deletions.
There are no files selected for viewing
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
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
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
59 changes: 59 additions & 0 deletions
59
library/src/main/java/software/amazon/location/auth/ApiKeyCredentialsProvider.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package software.amazon.location.auth | ||
|
||
import android.content.Context | ||
import software.amazon.location.auth.utils.Constants.API_KEY | ||
|
||
/** | ||
* Provides API key credentials for accessing services and manages their storage. | ||
*/ | ||
class ApiKeyCredentialsProvider { | ||
private var securePreferences: EncryptedSharedPreferences? = null | ||
|
||
/** | ||
* Initializes the provider and saves the provided API key. | ||
* @param context The application context. | ||
* @param apiKey The API key to save. | ||
*/ | ||
constructor(context: Context, apiKey: String) { | ||
initialize(context) | ||
saveCredentials(apiKey) | ||
} | ||
|
||
/** | ||
* Initializes the provider and retrieves the API key from the cache. | ||
* @param context The application context. | ||
* @throws Exception If no credentials are found in the cache. | ||
*/ | ||
constructor(context: Context) { | ||
initialize(context) | ||
val apiKey = getCachedCredentials() | ||
if (apiKey === null) throw Exception("No credentials found") | ||
} | ||
|
||
private fun initialize(context: Context) { | ||
securePreferences = EncryptedSharedPreferences(context, PREFS_NAME) | ||
securePreferences?.initEncryptedSharedPreferences() | ||
} | ||
|
||
private fun saveCredentials(apiKey: String) { | ||
if (securePreferences === null) throw Exception("Not initialized") | ||
securePreferences!!.put(API_KEY, apiKey) | ||
} | ||
|
||
/** | ||
* Retrieves the cached API key credentials. | ||
* @return The API key or null if not found. | ||
* @throws Exception If the AWSKeyValueStore is not initialized. | ||
*/ | ||
fun getCachedCredentials(): String? { | ||
if (securePreferences === null) throw Exception("Not initialized") | ||
return securePreferences!!.get(API_KEY) | ||
} | ||
|
||
/** | ||
* Clears the stored credentials. | ||
*/ | ||
fun clearCredentials() { | ||
securePreferences?.remove(API_KEY) | ||
} | ||
} |
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
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
Oops, something went wrong.