parent
d443d67895
commit
b0ee0c63d8
@ -3,6 +3,7 @@ package de.mm20.launcher2.msservices
|
|||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import android.widget.Toast
|
||||||
import androidx.core.content.edit
|
import androidx.core.content.edit
|
||||||
import com.azure.core.credential.AccessToken
|
import com.azure.core.credential.AccessToken
|
||||||
import com.azure.core.credential.TokenCredential
|
import com.azure.core.credential.TokenCredential
|
||||||
@ -43,13 +44,18 @@ class MicrosoftGraphApiHelper(val context: Context) {
|
|||||||
if (resId == 0) return null
|
if (resId == 0) return null
|
||||||
if (clientApplication == null) {
|
if (clientApplication == null) {
|
||||||
clientApplication = withContext(Dispatchers.IO) {
|
clientApplication = withContext(Dispatchers.IO) {
|
||||||
|
try {
|
||||||
PublicClientApplication.createSingleAccountPublicClientApplication(
|
PublicClientApplication.createSingleAccountPublicClientApplication(
|
||||||
context.applicationContext,
|
context.applicationContext,
|
||||||
resId
|
resId
|
||||||
)
|
)
|
||||||
|
} catch (e: MsalClientException) {
|
||||||
|
CrashReporter.logException(e)
|
||||||
|
null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return clientApplication!!
|
}
|
||||||
|
return clientApplication
|
||||||
}
|
}
|
||||||
|
|
||||||
private suspend fun acquireAccessToken(): Boolean {
|
private suspend fun acquireAccessToken(): Boolean {
|
||||||
@ -72,7 +78,11 @@ class MicrosoftGraphApiHelper(val context: Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
suspend fun login(context: Activity) {
|
suspend fun login(context: Activity) {
|
||||||
val clientApplication = getClientApplication() ?: return
|
val clientApplication = getClientApplication() ?: return run {
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
Toast.makeText(context, "Something went wrong, please check the logs", Toast.LENGTH_LONG).show()
|
||||||
|
}
|
||||||
|
}
|
||||||
suspendCoroutine<IAuthenticationResult?> {
|
suspendCoroutine<IAuthenticationResult?> {
|
||||||
clientApplication.signIn(context, "", SCOPES, object : AuthenticationCallback {
|
clientApplication.signIn(context, "", SCOPES, object : AuthenticationCallback {
|
||||||
override fun onSuccess(authenticationResult: IAuthenticationResult?) {
|
override fun onSuccess(authenticationResult: IAuthenticationResult?) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user