Skip to content

Commit 7f23855

Browse files
authored
Updated iOS Quickstart to use getCurrentAccount API for silent token acquisition
1 parent b50274a commit 7f23855

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

articles/active-directory/develop/quickstart-v2-ios.md

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -267,16 +267,21 @@ self.applicationContext!.acquireToken(with: parameters) { (result, error) in /*
267267
Apps shouldn't require their users to sign in every time they request a token. If the user has already signed in, this method allows apps to request tokens silently.
268268
269269
```swift
270-
guard let account = try self.applicationContext!.allAccounts().first else { return }
271-
272-
let silentParams = MSALSilentTokenParameters(scopes: kScopes, account: account)
273-
self.applicationContext!.acquireTokenSilent(with: silentParams) { (result, error) in /* Add your handling logic */}
270+
self.applicationContext!.getCurrentAccount(with: nil) { (currentAccount, previousAccount, error) in
271+
272+
guard let account = currentAccount else {
273+
return
274+
}
275+
276+
let silentParams = MSALSilentTokenParameters(scopes: self.kScopes, account: account)
277+
self.applicationContext!.acquireTokenSilent(with: silentParams) { (result, error) in /* Add your handling logic */}
278+
}
274279
```
275280
276281
> |Where: ||
277282
> |---------|---------|
278283
> | `scopes` | Contains the scopes being requested (that is, `[ "user.read" ]` for Microsoft Graph or `[ "<Application ID URL>/scope" ]` for custom Web APIs (`api://<Application ID>/access_as_user`) |
279-
> | `account` | The account a token is being requested for. This quickstart is about a single account application. If you want to build a multi-account app you'll need to define logic to identify which account to use for token requests using `applicationContext.account(forHomeAccountId: self.homeAccountId)` |
284+
> | `account` | The account a token is being requested for. This quickstart is about a single account application. If you want to build a multi-account app you'll need to define logic to identify which account to use for token requests using `accountsFromDeviceForParameters:completionBlock:` and passing correct `accountIdentifier` |
280285
281286
## Next steps
282287

0 commit comments

Comments
 (0)