Skip to content

Commit 6dbed9b

Browse files
authored
Merge pull request #89568 from MicrosoftDocs/release-ga-msal-apple
Release ga msal apple
2 parents d6fb90d + 2666697 commit 6dbed9b

31 files changed

+3126
-322
lines changed

articles/active-directory/develop/TOC.yml

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
href: v2-overview.md
1010
- name: Quickstarts
1111
items:
12-
- name: Set up a dev environment
12+
- name: Set up a tenant
1313
href: quickstart-create-new-tenant.md
1414
- name: Configure an application
1515
items:
@@ -49,7 +49,7 @@
4949
items:
5050
- name: Android
5151
href: quickstart-v2-android.md
52-
- name: iOS
52+
- name: iOS and macOS
5353
href: quickstart-v2-ios.md
5454
- name: Universal Windows Platform
5555
href: quickstart-v2-uwp.md
@@ -75,7 +75,7 @@
7575
items:
7676
- name: Android
7777
href: tutorial-v2-android.md
78-
- name: iOS
78+
- name: iOS and macOS
7979
href: tutorial-v2-ios.md
8080
- name: Universal Windows Platform
8181
href: tutorial-v2-windows-uwp.md
@@ -223,12 +223,14 @@
223223
items:
224224
- name: Overview
225225
href: msal-overview.md
226-
- name: Migration
226+
- name: Migration from ADAL
227227
items:
228228
- name: Migrate to MSAL.NET
229229
href: msal-net-migration.md
230230
- name: Migrate to MSAL.js
231231
href: msal-compare-msal-js-and-adal-js.md
232+
- name: Migrate to MSAL for iOS and MacOS
233+
href: migrate-objc-adal-msal.md
232234
- name: Migrate Xamarin apps using brokers from ADAL.NET to MSAL.NET
233235
href: msal-net-migration-ios-broker.md
234236
- name: Supported authentication flows
@@ -239,8 +241,6 @@
239241
href: msal-acquire-cache-tokens.md
240242
- name: Scopes for v1.0 apps
241243
href: msal-v1-app-scopes.md
242-
- name: Token cache serialization (.NET)
243-
href: msal-net-token-cache-serialization.md
244244
- name: Client applications
245245
items:
246246
- name: Client applications
@@ -257,18 +257,28 @@
257257
href: msal-handling-exceptions.md
258258
- name: Logging
259259
href: msal-logging.md
260-
- name: Single sign-on (JS)
261-
href: msal-js-sso.md
262-
- name: Prompt behavior (JS)
263-
href: msal-js-prompt-behavior.md
264-
- name: ADFS support (.NET)
265-
href: msal-net-adfs-support.md
260+
- name: Single sign-on
261+
items:
262+
- name: Single sign-on with MSAL.js
263+
href: msal-js-sso.md
264+
- name: Single sign-on with MSAL for iOS and macOS
265+
items:
266+
- name: SSO between MSAL apps
267+
href: single-sign-on-macos-ios.md
268+
- name: SSO between ADAL and MSAL apps
269+
href: sso-between-adal-msal-apps-macos-ios.md
270+
- name: Integrate with ADFS
271+
items:
272+
- name: ADFS support in MSAL.NET
273+
href: msal-net-adfs-support.md
266274
- name: Integrate with Azure AD B2C
267275
items:
268276
- name: JavaScript
269277
href: msal-b2c-overview.md
270278
- name: .NET
271279
href: msal-net-aad-b2c-considerations.md
280+
- name: iOS and macOS
281+
href: config-authority.md#b2c
272282
- name: Considerations and known issues
273283
items:
274284
- name: MSAL.NET
@@ -283,6 +293,10 @@
283293
href: msal-js-known-issues-ie-edge-browsers.md
284294
- name: Known issues- Safari
285295
href: msal-js-known-issues-safari-browser.md
296+
- name: MSAL for iOS and macOS
297+
items:
298+
- name: SSL issues
299+
href: ssl-issues.md
286300
- name: Authentication protocol
287301
items:
288302
- name: Application types and OAuth2.0
@@ -378,6 +392,8 @@
378392
items:
379393
- name: Acquire a token from the cache
380394
href: msal-net-acquire-token-silently.md
395+
- name: Token cache serialization
396+
href: msal-net-token-cache-serialization.md
381397
- name: Clear the token cache
382398
href: msal-net-clear-token-cache.md
383399
- name: Instantiate a public client with options
@@ -393,7 +409,21 @@
393409
- name: Avoid page reloads
394410
href: msal-js-avoid-page-reloads.md
395411
- name: Pass custom state in authentication requests
396-
href: msal-js-pass-custom-state-authentication-request.md
412+
href: msal-js-pass-custom-state-authentication-request.md
413+
- name: Prompt behavior
414+
href: msal-js-prompt-behavior.md
415+
- name: MSAL for iOS and macOS
416+
items:
417+
- name: Microsoft Authentication Library for iOS and macOS differences
418+
href: msal-differences-ios-macos.md
419+
- name: Configure keychain
420+
href: howto-v2-keychain-objc.md
421+
- name: Customize browsers and WebViews
422+
href: customize-webviews.md
423+
- name: Request custom claims
424+
href: request-custom-claims.md
425+
- name: Redirect URI configuration
426+
href: redirect-uris-ios.md
397427
- name: Work with Visual Studio
398428
items:
399429
- name: Use the Active Directory connected service
@@ -428,7 +458,7 @@
428458
href: v1-overview.md
429459
- name: Quickstarts
430460
items:
431-
- name: Set up a dev environment
461+
- name: Set up a tenant
432462
href: quickstart-create-new-tenant.md
433463
- name: Configure an application
434464
items:
@@ -468,7 +498,7 @@
468498
items:
469499
- name: Android
470500
href: quickstart-v1-android.md
471-
- name: iOS
501+
- name: iOS and MacOS
472502
href: quickstart-v1-ios.md
473503
- name: Windows Desktop .NET
474504
href: quickstart-v1-dotnet.md
Lines changed: 251 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,251 @@
1+
---
2+
title: Configure MSAL for iOS and macOS to use different identity providers | Microsoft identity platform
3+
description: Learn how to use different authorities such as B2C, sovereign clouds, and guest users, with MSAL for iOS and macOS.
4+
services: active-directory
5+
documentationcenter: ''
6+
author: tylermsft
7+
manager: CelesteDG
8+
editor: ''
9+
10+
ms.service: active-directory
11+
ms.subservice: develop
12+
ms.workload: identity
13+
ms.tgt_pltfrm: na
14+
ms.devlang: na
15+
ms.topic: conceptual
16+
ms.date: 08/28/2019
17+
ms.author: twhitney
18+
ms.reviewer: ''
19+
ms.custom: aaddev
20+
ms.collection: M365-identity-device-management
21+
---
22+
23+
# How to: Configure MSAL for iOS and macOS to use different identity providers
24+
25+
This article will show you how to configure your Microsoft authentication library app for iOS and macOS (MSAL) for different authorities such as Azure Active Directory (Azure AD), Business-to-Consumer (B2C), sovereign clouds, and guest users. Throughout this article, you can generally think of an authority as an identity provider.
26+
27+
## Default authority configuration
28+
29+
`MSALPublicClientApplication` is configured with a default authority URL of `https://login.microsoftonline.com/common`, which is suitable for most Azure Active Directory (AAD) scenarios. Unless you're implementing advanced scenarios like national clouds, or working with B2C, you won't need to change it.
30+
31+
> [!NOTE]
32+
> Modern authentication with Active Directory Federation Services as identity provider (ADFS) is not supported (see [ADFS for Developers](https://docs.microsoft.com/windows-server/identity/ad-fs/overview/ad-fs-scenarios-for-developers) for details). ADFS is supported through federation.
33+
34+
## Change the default authority
35+
36+
In some scenarios, such as business-to-consumer (B2C), you may need to change the default authority.
37+
38+
### B2C
39+
40+
To work with B2C, the [Microsoft Authentication Library (MSAL)](reference-v2-libraries.md) requires a different authority configuration. MSAL recognizes one authority URL format as B2C by itself. The recognized B2C authority format is `https://<host>/tfp/<tenant>/<policy>`, for example `https://login.microsoftonline.com/tfp/contoso.onmicrosoft.com/B2C_1_SignInPolicy`. However, you can also use any other supported B2C authority URLs by declaring authority as B2C authority explicitly.
41+
42+
To support an arbitrary URL format for B2C, `MSALB2CAuthority` can be set with an arbitrary URL, like this:
43+
44+
Objective-C
45+
```objc
46+
NSURL *authorityURL = [NSURL URLWithString:@"arbitrary URL"];
47+
MSALB2CAuthority *b2cAuthority = [[MSALB2CAuthority alloc] initWithURL:authorityURL
48+
error:&b2cAuthorityError];
49+
```
50+
Swift
51+
```swift
52+
guard let authorityURL = URL(string: "arbitrary URL") else {
53+
// Handle error
54+
return
55+
}
56+
let b2cAuthority = try MSALB2CAuthority(url: authorityURL)
57+
```
58+
59+
All B2C authorities that don't use the default B2C authority format must be declared as known authorities.
60+
61+
Add each different B2C authority to the known authorities list even if authorities only differ in policy.
62+
63+
Objective-C
64+
```objc
65+
MSALPublicClientApplicationConfig *b2cApplicationConfig = [[MSALPublicClientApplicationConfig alloc]
66+
initWithClientId:@"your-client-id"
67+
redirectUri:@"your-redirect-uri"
68+
authority:b2cAuthority];
69+
b2cApplicationConfig.knownAuthorities = @[b2cAuthority];
70+
```
71+
Swift
72+
```swift
73+
let b2cApplicationConfig = MSALPublicClientApplicationConfig(clientId: "your-client-id", redirectUri: "your-redirect-uri", authority: b2cAuthority)
74+
b2cApplicationConfig.knownAuthorities = [b2cAuthority]
75+
```
76+
77+
When your app requests a new policy, the authority URL needs to be changed because the authority URL is different for each policy.
78+
79+
To configure a B2C application, set `@property MSALAuthority *authority` with an instance of `MSALB2CAuthority` in `MSALPublicClientApplicationConfig` before creating `MSALPublicClientApplication`, like this:
80+
81+
Objective-C
82+
```ObjC
83+
// Create B2C authority URL
84+
NSURL *authorityURL = [NSURL URLWithString:@"https://login.microsoftonline.com/tfp/contoso.onmicrosoft.com/B2C_1_SignInPolicy"];
85+
86+
MSALB2CAuthority *b2cAuthority = [[MSALB2CAuthority alloc] initWithURL:authorityURL
87+
error:&b2cAuthorityError];
88+
if (!b2cAuthority)
89+
{
90+
// Handle error
91+
return;
92+
}
93+
94+
// Create MSALPublicClientApplication configuration
95+
MSALPublicClientApplicationConfig *b2cApplicationConfig = [[MSALPublicClientApplicationConfig alloc]
96+
initWithClientId:@"your-client-id"
97+
redirectUri:@"your-redirect-uri"
98+
authority:b2cAuthority];
99+
100+
// Initialize MSALPublicClientApplication
101+
MSALPublicClientApplication *b2cApplication =
102+
[[MSALPublicClientApplication alloc] initWithConfiguration:b2cApplicationConfig error:&error];
103+
104+
if (!b2cApplication)
105+
{
106+
// Handle error
107+
return;
108+
}
109+
```
110+
Swift
111+
```swift
112+
do{
113+
// Create B2C authority URL
114+
guard let authorityURL = URL(string: "https://login.microsoftonline.com/tfp/contoso.onmicrosoft.com/B2C_1_SignInPolicy") else {
115+
// Handle error
116+
return
117+
}
118+
let b2cAuthority = try MSALB2CAuthority(url: authorityURL)
119+
120+
// Create MSALPublicClientApplication configuration
121+
let b2cApplicationConfig = MSALPublicClientApplicationConfig(clientId: "your-client-id", redirectUri: "your-redirect-uri", authority: b2cAuthority)
122+
123+
// Initialize MSALPublicClientApplication
124+
let b2cApplication = try MSALPublicClientApplication(configuration: b2cApplicationConfig)
125+
} catch {
126+
// Handle error
127+
}
128+
```
129+
130+
### Sovereign clouds
131+
132+
If your app runs in a sovereign cloud, you may need to change the authority URL in the `MSALPublicClientApplication`. The following example sets the authority URL to work with the German AAD cloud:
133+
134+
Objective-C
135+
```objc
136+
NSURL *authorityURL = [NSURL URLWithString:@"https://login.microsoftonline.de/common"];
137+
MSALAuthority *sovereignAuthority = [MSALAuthority authorityWithURL:authorityURL error:&authorityError];
138+
139+
if (!sovereignAuthority)
140+
{
141+
// Handle error
142+
return;
143+
}
144+
145+
MSALPublicClientApplicationConfig *applicationConfig = [[MSALPublicClientApplicationConfig alloc]
146+
initWithClientId:@"your-client-id"
147+
redirectUri:@"your-redirect-uri"
148+
authority:sovereignAuthority];
149+
150+
151+
MSALPublicClientApplication *sovereignApplication = [[MSALPublicClientApplication alloc] initWithConfiguration:applicationConfig error:&error];
152+
153+
154+
if (!sovereignApplication)
155+
{
156+
// Handle error
157+
return;
158+
}
159+
```
160+
Swift
161+
```swift
162+
do{
163+
guard let authorityURL = URL(string: "https://login.microsoftonline.de/common") else {
164+
//Handle error
165+
return
166+
}
167+
let sovereignAuthority = try MSALAuthority(url: authorityURL)
168+
169+
let applicationConfig = MSALPublicClientApplicationConfig(clientId: "your-client-id", redirectUri: "your-redirect-uri", authority: sovereignAuthority)
170+
171+
let sovereignApplication = try MSALPublicClientApplication(configuration: applicationConfig)
172+
} catch {
173+
// Handle error
174+
}
175+
```
176+
177+
You may need to pass different scopes to each sovereign cloud. Which scopes to send depends on the resource that you're using. For example, you might use `"https://graph.microsoft.com/user.read"` in worldwide cloud, and `"https://graph.microsoft.de/user.read"` in German cloud.
178+
179+
### Signing a user into a specific tenant
180+
181+
When the authority URL is set to `"login.microsoftonline.com/common"`, the user will be signed into their home tenant. However, some apps may need to sign the user into a different tenant and some apps only work with a single tenant.
182+
183+
To sign the user into a specific tenant, configure `MSALPublicClientApplication` with a specific authority. For example:
184+
185+
`https://login.microsoftonline.com/469fdeb4-d4fd-4fde-991e-308a78e4bea4`
186+
187+
The following shows how to sign a user into a specific tenant:
188+
189+
Objective-C
190+
```objc
191+
NSURL *authorityURL = [NSURL URLWithString:@"https://login.microsoftonline.com/469fdeb4-d4fd-4fde-991e-308a78e4bea4"];
192+
MSALAADAuthority *tenantedAuthority = [[MSALAADAuthority alloc] initWithURL:authorityURL error:&authorityError];
193+
194+
if (!tenantedAuthority)
195+
{
196+
// Handle error
197+
return;
198+
}
199+
200+
MSALPublicClientApplicationConfig *applicationConfig = [[MSALPublicClientApplicationConfig alloc]
201+
initWithClientId:@"your-client-id"
202+
redirectUri:@"your-redirect-uri"
203+
authority:tenantedAuthority];
204+
205+
MSALPublicClientApplication *application =
206+
[[MSALPublicClientApplication alloc] initWithConfiguration:applicationConfig error:&error];
207+
208+
if (!application)
209+
{
210+
// Handle error
211+
return;
212+
}
213+
```
214+
Swift
215+
```swift
216+
do{
217+
guard let authorityURL = URL(string: "https://login.microsoftonline.com/469fdeb4-d4fd-4fde-991e-308a78e4bea4") else {
218+
//Handle error
219+
return
220+
}
221+
let tenantedAuthority = try MSALAADAuthority(url: authorityURL)
222+
223+
let applicationConfig = MSALPublicClientApplicationConfig(clientId: "your-client-id", redirectUri: "your-redirect-uri", authority: tenantedAuthority)
224+
225+
let application = try MSALPublicClientApplication(configuration: applicationConfig)
226+
} catch {
227+
// Handle error
228+
}
229+
```
230+
231+
## Supported authorities
232+
233+
### MSALAuthority
234+
235+
The `MSALAuthority` class is the base abstract class for the MSAL authority classes. Don't try to create instance of it using `alloc` or `new`. Instead, either create one of its subclasses directly (`MSALAADAuthority`, `MSALB2CAuthority`) or use the factory method `authorityWithURL:error:` to create subclasses using an authority URL.
236+
237+
Use the `url` property to get a normalized authority URL. Extra parameters and path components or fragments that aren't part of authority won't be in the returned normalized authority URL.
238+
239+
The following are subclasses of `MSALAuthority` that you can instantiate depending on the authority want to use.
240+
241+
### MSALAADAuthority
242+
243+
`MSALAADAuthority` represents an AAD authority. The authority url should be in the following format, where `<port>` is optional: `https://<host>:<port>/<tenant>`
244+
245+
### MSALB2CAuthority
246+
247+
`MSALB2CAuthority` represents a B2C authority. By default, the B2C authority url should be in the following format, where `<port>` is optional: `https://<host>:<port>/tfp/<tenant>/<policy>`. However, MSAL also supports other arbitrary B2C authority formats.
248+
249+
## Next steps
250+
251+
Learn more about [Authentication flows and application scenarios](authentication-flows-app-scenarios.md)

0 commit comments

Comments
 (0)