Skip to content
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

fix(rnta-msal): address deprecations #3101

Merged
merged 1 commit into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/twelve-jeans-wait.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@rnx-kit/react-native-test-app-msal": patch
---

Migrate away from deprecated `acquireTokenSilent(Array<(out) String!>, IAccount, String): IAuthenticationResult!`
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class MicrosoftAccountsActivity : AppCompatActivity() {

val sharedPreferences = getPreferences(MODE_PRIVATE)

val selectedAccountObserver = Observer<Account> { account ->
val selectedAccountObserver = Observer<Account?> { account ->
withTokenBroker { tokenBroker ->
if (tokenBroker.selectedAccount == account) {
return@withTokenBroker
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.Activity
import android.content.Context
import android.content.res.Resources.NotFoundException
import com.microsoft.identity.client.AcquireTokenParameters
import com.microsoft.identity.client.AcquireTokenSilentParameters
import com.microsoft.identity.client.AuthenticationCallback
import com.microsoft.identity.client.IAuthenticationResult
import com.microsoft.identity.client.IMultipleAccountPublicClientApplication
Expand All @@ -19,14 +20,13 @@ class TokenBroker private constructor(context: Context) {
const val EMPTY_GUID = "00000000-0000-0000-0000-000000000000"

@Volatile
private var INSTANCE: TokenBroker? = null
private var instance: TokenBroker? = null

fun getInstance(context: Context): TokenBroker =
INSTANCE ?: synchronized(this) {
INSTANCE ?: TokenBroker(context).also {
INSTANCE = it
}
fun getInstance(context: Context): TokenBroker = instance ?: synchronized(this) {
instance ?: TokenBroker(context).also {
instance = it
}
}
}

var selectedAccount: Account? = null
Expand Down Expand Up @@ -152,7 +152,13 @@ class TokenBroker private constructor(context: Context) {

val authority = multiAccountApp.configuration.defaultAuthority.authorityURL.toString()
try {
val result = multiAccountApp.acquireTokenSilent(scopes, account, authority)
val result = multiAccountApp.acquireTokenSilent(
AcquireTokenSilentParameters.Builder()
.forAccount(account)
.fromAuthority(authority)
.withScopes(scopes.toList())
.build()
)
val redirectUri = multiAccountApp.configuration.redirectUri
onTokenAcquired(AuthResult(result, redirectUri), null)
} catch (_: UiRequiredException) {
Expand Down
Loading