Skip to content

Commit a08f6d4

Browse files
authored
Merge pull request #224089 from henrymbuguakiarie/msid-freshness-2023-redirect-uris-ios
[msid][freshness] redirect-uris-ios [ADO-59520]
2 parents fa7804c + dde1e7c commit a08f6d4

File tree

1 file changed

+31
-35
lines changed

1 file changed

+31
-35
lines changed
Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
title: Use redirect URIs with MSAL (iOS/macOS)
3-
description: Learn about the differences between the Microsoft Authentication Library for ObjectiveC (MSAL for iOS and macOS) and Azure AD Authentication Library for ObjectiveC (ADAL.ObjC) and how to migrate between them.
3+
description: Learn about the differences between the Microsoft Authentication Library for Objective-C (MSAL for iOS and macOS) and Azure AD Authentication Library for Objective-C (ADAL.ObjC) and how to migrate between them.
44
services: active-directory
55
author: henrymbuguakiarie
66
manager: CelesteDG
@@ -9,73 +9,73 @@ ms.service: active-directory
99
ms.subservice: develop
1010
ms.topic: how-to
1111
ms.workload: identity
12-
ms.date: 08/28/2019
12+
ms.date: 01/18/2023
1313
ms.author: henrymbugua
1414
ms.reviewer: jak
1515
ms.custom: aaddev, has-adal-ref
1616
#Customer intent: As an application developer, I want to learn about how to use redirect URIs.
1717
---
1818

19-
# Using redirect URIs with the Microsoft authentication library for iOS and macOS
19+
# Using redirect URIs with the Microsoft Authentication Library (MSAL) for iOS and macOS
2020

2121
When a user authenticates, Azure Active Directory (Azure AD) sends the token to the app by using the redirect URI registered with the Azure AD application.
2222

23-
The Microsoft Authentication library (MSAL) requires that the redirect URI be registered with the Azure AD app in a specific format. MSAL uses a default redirect URI, if you don't specify one. The format is `msauth.[Your_Bundle_Id]://auth`.
23+
The MSAL requires that the redirect URI be registered with the Azure AD app in a specific format. MSAL uses a default redirect URI, if you don't specify one. The format is `msauth.[Your_Bundle_Id]://auth`.
2424

2525
The default redirect URI format works for most apps and scenarios, including brokered authentication and system web view. Use the default format whenever possible.
2626

27-
However, you may need to change the redirect URI for advanced scenarios, as described below.
27+
However, you may need to change the redirect URI for advanced scenarios, as described in the following section.
2828

2929
## Scenarios that require a different redirect URI
3030

31-
### Cross-app single sign on (SSO)
31+
### Cross-app single sign-on (SSO)
3232

33-
For the Microsoft Identity platform to share tokens across apps, each app needs to have the same client ID or application ID. This is the unique identifier provided when you registered your app in the portal (not the application bundle ID that you register per app with Apple).
33+
For the Microsoft identity platform to share tokens across apps, each app needs to have the same client ID or application ID. The client ID is the unique identifier provided when you registered your app in the Azure portal (not the application bundle ID that you register per app with Apple).
3434

3535
The redirect URIs need to be different for each iOS app. This allows the Microsoft identity service to uniquely identify different apps that share an application ID. Each application can have multiple redirect URIs registered in the Azure portal. Each app in your suite will have a different redirect URI. For example:
3636

3737
Given the following application registration in the Azure portal:
3838

39-
* Client ID: `ABCDE-12345` (this is a single client ID)
40-
* RedirectUris: `msauth.com.contoso.app1://auth`, `msauth.com.contoso.app2://auth`, `msauth.com.contoso.app3://auth`
39+
- Client ID: `ABCDE-12345`
40+
- RedirectUris: `msauth.com.contoso.app1://auth`, `msauth.com.contoso.app2://auth`, `msauth.com.contoso.app3://auth`
4141

4242
App1 uses redirect `msauth.com.contoso.app1://auth`.\
4343
App2 uses `msauth.com.contoso.app2://auth`.\
4444
App3 uses `msauth.com.contoso.app3://auth`.
4545

4646
### Migrating from ADAL to MSAL
4747

48-
When migrating code that used the Azure AD Authentication Library (ADAL) to MSAL, you may already have a redirect URI configured for your app. You can continue using the same redirect URI as long as your ADAL app was configured to support brokered scenarios and your redirect URI satisfies the MSAL redirect URI format requirements.
48+
When migrating code that used the Azure Active Directory Authentication Library (ADAL) to MSAL, you may already have a redirect URI configured for your app. You can continue using the same redirect URI as long as your ADAL app was configured to support brokered scenarios and your redirect URI satisfies the MSAL redirect URI format requirements.
4949

5050
## MSAL redirect URI format requirements
5151

52-
* The MSAL redirect URI must be in the form `<scheme>://host`
52+
- The MSAL redirect URI must be in the form `<scheme>://host`
5353

54-
Where `<scheme>` is a unique string that identifies your app. It's primarily based on the Bundle Identifier of your application to guarantee uniqueness. For example, if your app's Bundle ID is `com.contoso.myapp`, your redirect URI would be in the form: `msauth.com.contoso.myapp://auth`.
54+
Where `<scheme>` is a unique string that identifies your app. It's primarily based on the Bundle Identifier of your application to guarantee uniqueness. For example, if your app's Bundle ID is `com.contoso.myapp`, your redirect URI would be in the form: `msauth.com.contoso.myapp://auth`.
5555

56-
If you're migrating from ADAL, your redirect URI will likely have this format: `<scheme>://[Your_Bundle_Id]`, where `scheme` is a unique string. This format will continue to work when you use MSAL.
56+
If you're migrating from ADAL, your redirect URI will likely have this format: `<scheme>://[Your_Bundle_Id]`, where `scheme` is a unique string. The format will continue to work when you use MSAL.
5757

58-
* `<scheme>` must be registered in your app's Info.plist under `CFBundleURLTypes > CFBundleURLSchemes`. In this example, Info.plist has been opened as source code:
58+
- `<scheme>` must be registered in your app's Info.plist under `CFBundleURLTypes > CFBundleURLSchemes`. In this example, Info.plist has been opened as source code:
5959

60-
```xml
61-
<key>CFBundleURLTypes</key>
62-
<array>
63-
<dict>
64-
<key>CFBundleURLSchemes</key>
65-
<array>
66-
<string>msauth.[BUNDLE_ID]</string>
67-
</array>
68-
</dict>
69-
</array>
70-
```
60+
```xml
61+
<key>CFBundleURLTypes</key>
62+
<array>
63+
<dict>
64+
<key>CFBundleURLSchemes</key>
65+
<array>
66+
<string>msauth.[BUNDLE_ID]</string>
67+
</array>
68+
</dict>
69+
</array>
70+
```
7171

7272
MSAL will verify if your redirect URI registers correctly, and return an error if it's not.
73-
74-
* If you want to use universal links as a redirect URI, the `<scheme>` must be `https` and doesn't need to be declared in `CFBundleURLSchemes`. Instead, configure the app and domain per Apple's instructions at [Universal Links for Developers](https://developer.apple.com/ios/universal-links/) and call the `handleMSALResponse:sourceApplication:` method of `MSALPublicClientApplication` when your application is opened through a universal link.
73+
74+
- If you want to use universal links as a redirect URI, the `<scheme>` must be `https` and doesn't need to be declared in `CFBundleURLSchemes`. Instead, configure the app and domain per Apple's instructions at [Universal Links for Developers](https://developer.apple.com/ios/universal-links/) and call the `handleMSALResponse:sourceApplication:` method of `MSALPublicClientApplication` when your application is opened through a universal link.
7575

7676
## Use a custom redirect URI
7777

78-
To use a custom redirect URI, pass the `redirectUri` parameter to `MSALPublicClientApplicationConfig` and pass that object to `MSALPublicClientApplication` when you initialize the object. If the redirect URI is invalid, the initializer will return `nil` and set the `redirectURIError`with additional information. For example:
78+
To use a custom redirect URI, pass the `redirectUri` parameter to `MSALPublicClientApplicationConfig` and pass that object to `MSALPublicClientApplication` when you initialize the object. If the redirect URI is invalid, the initializer will return `nil` and set the `redirectURIError`with additional information. For example:
7979

8080
Objective-C:
8181

@@ -97,14 +97,12 @@ let config = MSALPublicClientApplicationConfig(clientId: "your-client-id",
9797
authority: authority)
9898
do {
9999
let application = try MSALPublicClientApplication(configuration: config)
100-
// continue on with application
100+
// continue on with application
101101
} catch let error as NSError {
102102
// handle error here
103-
}
103+
}
104104
```
105105

106-
107-
108106
## Handle the URL opened event
109107

110108
Your application should call MSAL when it receives any response through URL schemes or universal links. Call the `handleMSALResponse:sourceApplication:` method of `MSALPublicClientApplication` when your application is opened. Here's an example for custom schemes:
@@ -116,7 +114,7 @@ Objective-C:
116114
openURL:(NSURL *)url
117115
options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
118116
{
119-
return [MSALPublicClientApplication handleMSALResponse:url
117+
return [MSALPublicClientApplication handleMSALResponse:url
120118
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]];
121119
}
122120
```
@@ -129,8 +127,6 @@ func application(_ app: UIApplication, open url: URL, options: [UIApplication.Op
129127
}
130128
```
131129

132-
133-
134130
## Next steps
135131

136132
Learn more about [Authentication flows and application scenarios](authentication-flows-app-scenarios.md)

0 commit comments

Comments
 (0)