Skip to content

Commit 6977637

Browse files
authored
Merge pull request #66 from Azure-Samples/kaisong1990/update-app-json
Update app.json file to support dynamic configuration in azure portal
2 parents 3e70b5a + 42dfa0f commit 6977637

File tree

4 files changed

+82
-59
lines changed

4 files changed

+82
-59
lines changed

AppCreationScripts/apps.json

Lines changed: 47 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,48 @@
11
{
2-
"Sample": {
3-
"Title": "Calling Microsoft Graph from an iOS app",
4-
"Level": 400,
5-
"Client": "iOS"
6-
},
7-
"AppRegistrations": [
8-
{
9-
"x-ms-id": "active-directory-ios-swift-native-v2",
10-
"x-ms-name": "ios-swift-native-v2",
11-
"x-ms-version": "2.0",
12-
"replyUrlsWithType": [
13-
{
14-
"url": "msal{AppId}://auth",
15-
"type": "InstalledClient"
16-
}
17-
],
18-
"requiredResourceAccess": [
19-
{
20-
"x-ms-resourceAppName": "Microsoft Graph",
21-
"resourceAppId": "00000003-0000-0000-c000-000000000000",
22-
"resourceAccess": [
23-
{
24-
"id": "e1fe6dd8-ba31-4d61-89e7-88639da4683d",
25-
"type": "Scope",
26-
"x-ms-name": "user.read"
27-
}
28-
]
29-
}
30-
]
31-
}
32-
]
33-
}
2+
"Sample": {
3+
"Title": "Calling Microsoft Graph from an iOS app",
4+
"Level": 400,
5+
"Client": "iOS"
6+
},
7+
"AppRegistrations": [{
8+
"x-ms-id": "active-directory-ios-swift-native-v2",
9+
"x-ms-name": "ios-swift-native-v2",
10+
"x-ms-version": "2.0",
11+
"replyUrlsWithType": [{
12+
"url": "msauth.<bundleId>://auth",
13+
"type": "InstalledClient"
14+
}],
15+
"requiredResourceAccess": [{
16+
"x-ms-resourceAppName": "Microsoft Graph",
17+
"resourceAppId": "00000003-0000-0000-c000-000000000000",
18+
"resourceAccess": [{
19+
"id": "e1fe6dd8-ba31-4d61-89e7-88639da4683d",
20+
"type": "Scope",
21+
"x-ms-name": "user.read"
22+
}]
23+
}],
24+
"codeConfigurations": [{
25+
"settingFile": "/MSALiOS/ViewController.swift",
26+
"replaceTokens": {
27+
"appId": "66855f8a-60cd-445e-a9bb-8cd8eadbd3fa",
28+
"authorityEndpointHost": "https://login.microsoftonline.com/",
29+
"tenantId": "common",
30+
"msgraphEndpointHost": "https://graph.microsoft.com/",
31+
"redirectUri": "msauth.com.microsoft.identitysample.MSALiOS://auth"
32+
}
33+
},
34+
{
35+
"settingFile": "/MSALiOS/Info.plist",
36+
"replaceTokens": {
37+
"bundleId": "com.microsoft.identitysample.MSALiOS"
38+
}
39+
},
40+
{
41+
"settingFile": "/MSALiOS.xcodeproj/project.pbxproj",
42+
"replaceTokens": {
43+
"bundleId": "com.microsoft.identitysample.MSALiOS"
44+
}
45+
}
46+
]
47+
}]
48+
}

MSALiOS/ViewController.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class ViewController: UIViewController, UITextFieldDelegate, URLSessionDelegate
3636
let kClientID = "66855f8a-60cd-445e-a9bb-8cd8eadbd3fa"
3737
let kGraphEndpoint = "https://graph.microsoft.com/"
3838
let kAuthority = "https://login.microsoftonline.com/common"
39+
let kRedirectUri = "msauth.com.microsoft.identitysample.MSALiOS://auth"
3940

4041
let kScopes: [String] = ["user.read"]
4142

@@ -120,7 +121,9 @@ extension ViewController {
120121

121122
let authority = try MSALAADAuthority(url: authorityURL)
122123

123-
let msalConfiguration = MSALPublicClientApplicationConfig(clientId: kClientID, redirectUri: nil, authority: authority)
124+
let msalConfiguration = MSALPublicClientApplicationConfig(clientId: kClientID,
125+
redirectUri: kRedirectUri,
126+
authority: authority)
124127
self.applicationContext = try MSALPublicClientApplication(configuration: msalConfiguration)
125128
self.initWebViewParams()
126129
}

README.md

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ description: "The MSAL preview library for iOS and macOS gives your app the abil
88
urlFragment: ios-ms-graph-api
99
---
1010

11-
# MSAL iOS Swift Microsoft Graph API Sample
11+
# MSAL iOS Swift Microsoft Graph API Sample
1212

1313
![Build Badge](https://identitydivision.visualstudio.com/_apis/public/build/definitions/a7934fdd-dcde-4492-a406-7fad6ac00e17/523/badge)
1414

1515
| [Getting Started](https://docs.microsoft.com/azure/active-directory/develop/guidedsetups/active-directory-ios)| [Library](https://github.com/AzureAD/microsoft-authentication-library-for-objc) | [API Reference](https://azuread.github.io/docs/objc/) | [Support](README.md#feedback,community-help,-and-support)
1616
| --- | --- | --- | --- |
1717

18-
The MSAL library for iOS gives your app the ability to begin using the [Microsoft identity platform](https://aka.ms/aaddev) by supporting [Microsoft Azure Active Directory](https://azure.microsoft.com/en-us/services/active-directory/) and [Microsoft Accounts](https://account.microsoft.com) in a converged experience using industry standard OAuth2 and OpenID Connect. This sample demonstrates all the normal lifecycles your application should experience, including:
18+
The MSAL library for iOS gives your app the ability to begin using the [Microsoft identity platform](https://aka.ms/aaddev) by supporting [Microsoft Azure Active Directory](https://azure.microsoft.com/en-us/services/active-directory/) and [Microsoft Accounts](https://account.microsoft.com) in a converged experience using industry standard OAuth2 and OpenID Connect. This sample demonstrates all the normal lifecycle your application should experience, including:
1919

2020
- How to get a token
2121
- How to refresh a token
@@ -35,7 +35,7 @@ To run this sample, you'll need:
3535
* Xcode
3636
* An internet connection
3737

38-
## Step 1:
38+
## Step 1:
3939

4040
## 1A: Clone or download this repository
4141

@@ -58,13 +58,9 @@ $ pod install
5858
$ open MSALiOS.xcworkspace
5959
```
6060

61-
## Step 2: (Optional)
61+
## Step 2: Register your App (Optional)
6262

63-
## 2A: Register your App
64-
65-
This app comes pre-configured for testing. If you would like to register your own app, please follow the steps below.
66-
67-
To Register an app:
63+
This app comes pre-configured for testing. If you would like to register your own app, please follow the steps below.
6864

6965
1. Sign in to the [Azure portal](https://portal.azure.com) using either a work or school account.
7066
2. In the left-hand navigation pane, select the **Azure Active Directory** blade, and then select **App registrations**.
@@ -76,10 +72,18 @@ To Register an app:
7672
5. After the app is created, you'll land on your app management page. Take note of the **Application (client) ID** as this would be needed for the step 2B below.
7773
6. Click **Authentication**, and add new Redirect URI with type **Public client (mobile & desktop)**. Enter redirect URI in format: `msauth.<app_bundle_id>://auth`. Replace <app_bundle_id> with the **Bundle Identifier** for your application.
7874
7. Hit the **Save** button in the top left, to save these updates.
75+
8. Click **Make this change for me** and then download the code sample for iOS
76+
77+
## Step 3: Run the sample
78+
79+
1. Click the Run Button in the top menu or go to Product from the menu tab and click Run.
80+
2. Once the sample app launches, click on the 'Call Microsoft Graph API' button to go through the sign in flow and see the results from Microsoft Graph.
7981

80-
## 2B: Configure your application
82+
## How to add MSAL library into your existing Xcode project
8183

82-
1. Update your application's redirect URI scheme in the `Info.plist` file by replacing `msauth.com.microsoft.identitysample.MSALiOS` . Redirect URI scheme follows the format `msauth.[app_bundle_id]`. Make sure to substitue [app_bundle_id] with the **Bundle Identifier** for your application.
84+
## Step 1: Configure your application Info.plist
85+
86+
Add URI scheme in the `Info.plist`. Redirect URI scheme follows the format `msauth.[app_bundle_id]`. Make sure to substitute [app_bundle_id] with the **Bundle Identifier** for your application.
8387

8488
```xml
8589
<key>CFBundleURLTypes</key>
@@ -93,52 +97,53 @@ To Register an app:
9397
</array>
9498
```
9599

96-
2. Configure your application defaults
100+
## Step 2: Configure your application defaults
97101

98-
In the `ViewControler.swift` file, update the `kClientID` variable with your Application (client) ID.
102+
In your app, add the `kClientID` variable with your Application (client) ID.
99103

100104
```swift
101-
// Update the client ID below with the one you received in the portal. Below ID is for running the sample app only.
102-
103-
let kClientID = "66855f8a-60cd-445e-a9bb-8cd8eadbd3fa"
105+
// For example, you can declare a client id in this way. Below ID is just a sample.
106+
107+
let kClientID = "66855f8a-60cd-445e-a9bb-8cd8eadbd3fa"
104108
```
105109

106-
In the `ViewControler.swift` file, update the `kAuthority` variable with your Azure AD and Microsoft Graph endpoints for your national cloud. For global access, use following values:
110+
Add variables with your Azure AD authority and Microsoft Graph endpoint for your national cloud.
107111

108-
```objective-c
112+
```swift
109113
let kGraphEndpoint = "https://graph.microsoft.com/"
110114
let kAuthority = "https://login.microsoftonline.com/common"
111115
```
112116

113117
Other endpoints are documented [here](https://docs.microsoft.com/en-us/graph/deployments#app-registration-and-token-service-root-endpoints). For example, to run the sample with AzureAD Germany, use following:
114118

115-
```objective-c
119+
```swift
116120
let kGraphEndpoint = "https://graph.microsoft.de/"
117121
let kAuthority = "https://login.microsoftonline.de/common"
118122
```
119123

120-
## Step 3: Run the sample
124+
## Step 3: Configure Xcode project settings
121125

122-
1. Click the Run Button in the top menu or go to Product from the menu tab and click Run.
123-
2. Once the sample app launches, click on the 'Call Microsoft Graph API' button to go through the sign in flow and see the results from Microsoft Graph.
126+
Add a new keychain group to your project **Signing & Capabilities**. The keychain group should be `com.microsoft.adalcache` on iOS.
127+
128+
![Xcode UI displaying how the the keychain group should be set up](./images/iosintro-keychainShare.png)
124129

125130
## Feedback, Community Help, and Support
126131

127-
We use [Stack Overflow](http://stackoverflow.com/questions/tagged/msal) with the community to provide support. We highly recommend you ask your questions on Stack Overflow first and browse existing issues to see if someone has asked your question before.
132+
We use [Stack Overflow](http://stackoverflow.com/questions/tagged/msal) with the community to provide support. We highly recommend you ask your questions on Stack Overflow first and browse existing issues to see if someone has asked your question before.
128133

129-
If you find a bug or have a feature request, please raise the issue on [GitHub Issues](../../issues).
134+
If you find a bug or have a feature request, please raise the issue on [GitHub Issues](../../issues).
130135

131136
To provide a recommendation, visit our [User Voice page](https://feedback.azure.com/forums/169401-azure-active-directory).
132137

133138
## Contribute
134139

135-
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
140+
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
136141

137142
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact [[email protected]](mailto:[email protected]) with any additional questions or comments.
138143

139144
## Security Library
140145

141-
This library controls how users sign-in and access services. We recommend you always take the latest version of our library in your app when possible. We use [semantic versioning](http://semver.org) so you can control the risk associated with updating your app. As an example, always downloading the latest minor version number (e.g. x.*y*.x) ensures you get the latest security and feature enhanements but our API surface remains the same. You can always see the latest version and release notes under the Releases tab of GitHub.
146+
This library controls how users sign-in and access services. We recommend you always take the latest version of our library in your app when possible. We use [semantic versioning](http://semver.org) so you can control the risk associated with updating your app. As an example, always downloading the latest minor version number (e.g. x.*y*.x) ensures you get the latest security and feature enhancements but our API surface remains the same. You can always see the latest version and release notes under the Releases tab of GitHub.
142147

143148
## Security Reporting
144149

images/iosintro-keychainShare.png

14.3 KB
Loading

0 commit comments

Comments
 (0)