-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Applied appauth libs for OAuth.| #716
- Loading branch information
Showing
10 changed files
with
96 additions
and
131 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
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
49 changes: 0 additions & 49 deletions
49
...rc/main/java/com/flowcrypt/email/api/retrofit/response/oauth2/MicrosoftAccountResponse.kt
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -15,6 +15,7 @@ import com.flowcrypt.email.api.retrofit.ApiRepository | |
import com.flowcrypt.email.api.retrofit.FlowcryptApiRepository | ||
import com.flowcrypt.email.api.retrofit.response.base.Result | ||
import kotlinx.coroutines.launch | ||
import net.openid.appauth.AuthorizationRequest | ||
|
||
|
||
/** | ||
|
@@ -27,14 +28,15 @@ class OAuth2AuthCredentialsViewModel(application: Application) : BaseAndroidView | |
private val apiRepository: ApiRepository = FlowcryptApiRepository() | ||
val microsoftOAuth2TokenLiveData = MutableLiveData<Result<AuthCredentials>>() | ||
|
||
fun getMicrosoftOAuth2Token(requestCode: Long = 0L, authorizeCode: String) { | ||
fun getMicrosoftOAuth2Token(requestCode: Long = 0L, authorizeCode: String, authRequest: AuthorizationRequest) { | ||
viewModelScope.launch { | ||
microsoftOAuth2TokenLiveData.postValue(Result.loading()) | ||
val microsoftOAuth2TokenResponseResultForProfile = apiRepository.getMicrosoftOAuth2Token( | ||
requestCode = requestCode, | ||
context = getApplication(), | ||
authorizeCode = authorizeCode, | ||
scopes = OAuth2Helper.SCOPE_MICROSOFT_OAUTH2_FOR_PROFILE | ||
scopes = OAuth2Helper.SCOPE_MICROSOFT_OAUTH2_FOR_PROFILE, | ||
codeVerifier = authRequest.codeVerifier ?: "" | ||
) | ||
|
||
if (microsoftOAuth2TokenResponseResultForProfile.status != Result.Status.SUCCESS) { | ||
|
@@ -54,19 +56,17 @@ class OAuth2AuthCredentialsViewModel(application: Application) : BaseAndroidView | |
return@launch | ||
} | ||
|
||
//validate id_token | ||
|
||
|
||
val tokenForProfile = microsoftOAuth2TokenResponseResultForProfile.data?.accessToken | ||
if (tokenForProfile == null) { | ||
microsoftOAuth2TokenLiveData.postValue(Result.exception(NullPointerException("token is null"))) | ||
return@launch | ||
} | ||
|
||
val microsoftAccount = apiRepository.getMicrosoftAccountInfo( | ||
requestCode = requestCode, | ||
context = getApplication(), | ||
bearerToken = tokenForProfile | ||
) | ||
|
||
val userEmailAddress = microsoftAccount.data?.userPrincipalName | ||
val userEmailAddress = "[email protected]"//microsoftAccount.data?.userPrincipalName | ||
if (userEmailAddress == null) { | ||
microsoftOAuth2TokenLiveData.postValue(Result.exception(NullPointerException("User email is null"))) | ||
return@launch | ||
|
@@ -76,7 +76,8 @@ class OAuth2AuthCredentialsViewModel(application: Application) : BaseAndroidView | |
requestCode = requestCode, | ||
context = getApplication(), | ||
authorizeCode = authorizeCode, | ||
scopes = OAuth2Helper.SCOPE_MICROSOFT_OAUTH2_FOR_MAIL | ||
scopes = OAuth2Helper.SCOPE_MICROSOFT_OAUTH2_FOR_MAIL, | ||
codeVerifier = authRequest.codeVerifier ?: "" | ||
) | ||
|
||
if (microsoftOAuth2TokenResponseResultForEmail.status != Result.Status.SUCCESS) { | ||
|
@@ -104,7 +105,7 @@ class OAuth2AuthCredentialsViewModel(application: Application) : BaseAndroidView | |
} | ||
|
||
val recommendAuthCredentials = EmailProviderSettingsHelper.getBaseSettings( | ||
microsoftAccount.data.userPrincipalName, tokenForEmail)?.copy(useOAuth2 = true) | ||
"microsoftAccount.data.userPrincipalName", tokenForEmail)?.copy(useOAuth2 = true) | ||
|
||
microsoftOAuth2TokenLiveData.postValue(Result.success(recommendAuthCredentials!!)) | ||
} | ||
|
Oops, something went wrong.