Skip to content

Commit c7ecb69

Browse files
authored
Merge pull request #50672 from oldalton/patch-4
Updated iOS Quickstart to use getCurrentAccount API for silent token acquisition
2 parents 43566b7 + 9047c37 commit c7ecb69

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -267,25 +267,30 @@ 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
283-
Try out the iOS tutorial for a complete step-by-step guide on building applications, including a complete explanation of this quickstart.
288+
Try out the tutorial for iOS and macOS for a complete step-by-step guide on building applications, including a complete explanation of this quickstart.
284289
285290
### Learn how to create the application used in this quickstart
286291
287292
> [!div class="nextstepaction"]
288-
> [Call Graph API iOS tutorial](https://docs.microsoft.com/azure/active-directory/develop/guidedsetups/active-directory-ios)
293+
> [Call Graph API tutorial for iOS and macOS](https://docs.microsoft.com/azure/active-directory/develop/guidedsetups/active-directory-ios)
289294
290295
[!INCLUDE [Help and support](../../../includes/active-directory-develop-help-support-include.md)]
291296

0 commit comments

Comments
 (0)