-
Notifications
You must be signed in to change notification settings - Fork 0
[Goals for Onboarding] #104
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
Merged
+435
−97
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c6de945
started goals page for onboarding
isiahpwilliams ae1b752
finished ui
isiahpwilliams 4739034
added screen to onboarding flow
isiahpwilliams 5f559f4
rebasing changes
isiahpwilliams a9f3ab0
finished redoing goals onboarding screen
isiahpwilliams 08ce70f
connected goal onboarding to viewmodel
isiahpwilliams f0f633a
finished onboarding networking
isiahpwilliams 53f8032
deleted unused files
isiahpwilliams c761bdc
Update app/src/main/java/com/cornellappdev/uplift/ui/viewmodels/onboa…
isiahpwilliams 39fc3a7
Update app/src/main/java/com/cornellappdev/uplift/ui/viewmodels/onboa…
isiahpwilliams 8c6f84d
Update app/src/main/java/com/cornellappdev/uplift/data/repositories/U…
isiahpwilliams 8f7bb3c
added token manager and error handling
isiahpwilliams 7f59e9b
resolved merge conflicts
isiahpwilliams 99d0c93
added auth interceptor and token manager
isiahpwilliams b6937eb
fixed copilot suggestions
isiahpwilliams File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Binary file not shown.
This file contains hidden or 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 hidden or 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 hidden or 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
21 changes: 21 additions & 0 deletions
21
app/src/main/java/com/cornellappdev/uplift/data/repositories/AuthInterceptor.kt
This file contains hidden or 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,21 @@ | ||
| package com.cornellappdev.uplift.data.repositories | ||
|
|
||
| import okhttp3.Interceptor | ||
| import okhttp3.Response | ||
| import javax.inject.Inject | ||
| import javax.inject.Singleton | ||
|
|
||
| @Singleton | ||
| class AuthInterceptor @Inject constructor( | ||
| private val tokenManager: TokenManager | ||
| ) : Interceptor { | ||
| override fun intercept(chain: Interceptor.Chain): Response { | ||
| val token = tokenManager.getAccessToken() | ||
| val request = chain.request().newBuilder().apply { | ||
| if (token != null) { | ||
| addHeader("Authorization", "Bearer $token") | ||
| } | ||
| }.build() | ||
| return chain.proceed(request) | ||
| } | ||
| } |
This file contains hidden or 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
65 changes: 65 additions & 0 deletions
65
app/src/main/java/com/cornellappdev/uplift/data/repositories/TokenManager.kt
This file contains hidden or 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,65 @@ | ||
| package com.cornellappdev.uplift.data.repositories | ||
|
|
||
| import android.content.Context | ||
| import android.content.SharedPreferences | ||
| import android.util.Log | ||
| import androidx.security.crypto.EncryptedSharedPreferences | ||
| import androidx.security.crypto.MasterKey | ||
| import androidx.core.content.edit | ||
| import dagger.hilt.android.qualifiers.ApplicationContext | ||
| import javax.inject.Inject | ||
| import javax.inject.Singleton | ||
|
|
||
| @Singleton | ||
| class TokenManager @Inject constructor(@ApplicationContext private val context: Context) { | ||
| private val fileName = "encrypted_tokens" | ||
|
|
||
| // Initialize EncryptedSharedPreferences | ||
| private val sharedPreferences: SharedPreferences? by lazy { | ||
| try { | ||
| createEncryptedPrefs() | ||
| } catch (e: Exception) { | ||
| Log.e("TokenManager", "Failed to initialize EncryptedSharedPreferences", e) | ||
| // Clear corrupted state | ||
| context.deleteSharedPreferences(fileName) | ||
| try { | ||
| // Could have failed due to previous corrupted state | ||
| // One more attempt after cleaning the corruption | ||
| createEncryptedPrefs() | ||
| } catch (retryException: Exception) { | ||
| // Probably broken return null | ||
| Log.e("TokenManager", "Failed to initialize EncryptedSharedPreferences again", retryException) | ||
| null | ||
| } | ||
| } | ||
| } | ||
|
|
||
| private fun createEncryptedPrefs(): SharedPreferences { | ||
| val masterKey = MasterKey.Builder(context) | ||
| .setKeyScheme(MasterKey.KeyScheme.AES256_GCM) | ||
| .build() | ||
|
|
||
| return EncryptedSharedPreferences.create( | ||
| context, | ||
| fileName, | ||
| masterKey, | ||
| EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV, | ||
| EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM | ||
| ) | ||
| } | ||
|
|
||
| fun saveTokens(accessToken: String, refreshToken: String) { | ||
| sharedPreferences?.edit { | ||
| putString("access_token", accessToken) | ||
| putString("refresh_token", refreshToken) | ||
| } | ||
| } | ||
|
|
||
| fun getAccessToken(): String? = sharedPreferences?.getString("access_token", null) | ||
|
|
||
| fun getRefreshToken(): String? = sharedPreferences?.getString("refresh_token", null) | ||
|
|
||
| fun clearTokens() { | ||
| sharedPreferences?.edit { clear() } | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TokenManagerfalls back to plainSharedPreferenceswhenEncryptedSharedPreferencesinitialization fails (catch block). That means access/refresh tokens may be stored unencrypted on some devices, defeating the purpose of introducing encrypted storage. Prefer failing closed here (e.g., clear tokens and force re-auth) rather than silently storing tokens in plaintext.