开源软件名称(OpenSource Name):AzureAD/azure-activedirectory-library-for-objc开源软件地址(OpenSource Url):https://github.com/AzureAD/azure-activedirectory-library-for-objc开源编程语言(OpenSource Language):Objective-C 97.8%开源软件介绍(OpenSource Introduction):This library, ADAL for iOS and macOS, will no longer receive new feature improvements. Instead, use the new library MSAL for iOS and macOS.
Microsoft Azure Active Directory Authentication Library (ADAL) for iOS and macOS=====================================
Release VersionsWe recommend remaining up-to-date with the latest version of ADAL. The best place to check what the most recent version is is the releases page on GitHub, you can also subscribe the the Atom Feed from GitHub, or use a 3rd party tool like Sibbell to receive emails when a new version is released. The only approved way to get the latest version is through a tagged release on GitHub, or a tool that relies on that data. Tools like CocoaPods can make it easier to set up your project dependencies and update to the latest release. ADAL follows the GitFlow branching model. You should never pull an ADAL version for release from any branch other then master, any other branch is for versions of ADAL still in development or testing, and are subject to change. NOTE:
The ADAL SDK for iOS and macOS gives you the ability to add support for Work Accounts to your application with just a few lines of additional code. This SDK gives your application the full functionality of Microsoft Azure AD, including industry standard protocol support for OAuth2, Web API integration with user level consent, and two factor authentication support. Best of all, it’s FOSS (Free and Open Source Software) so that you can participate in the development process as we build these libraries. Contribution HistorySamples and DocumentationWe provide a full suite of sample applications and documentation on GitHub to help you get started with learning the Azure Identity system. This includes tutorials for native clients such as Windows, Windows Phone, iOS, macOS, Android, and Linux. We also provide full walkthroughs for authentication flows such as OAuth2, OpenID Connect, Graph API, and other awesome features. Azure Identity samples for iOS is here: https://github.com/AzureADSamples/NativeClient-iOS Community Help and SupportWe leverage Stack Overflow to work with the community on supporting Azure Active Directory and its SDKs, including this one! We highly recommend you ask your questions on Stack Overflow (we're all on there!) Also browser existing issues to see if someone has had your question before. We recommend you use the "adal" tag so we can see it! Here is the latest Q&A on Stack Overflow for ADAL: http://stackoverflow.com/questions/tagged/adal SSO and Conditional Access SupportThis library allows your application to support our Enterprise Mobility Suite, including Conditional Access, so businesses can use your application in their secure environment. To configure your application to support these scenarios, please read this document: How to enable cross-app SSO on iOS using ADAL Security ReportingIf you find a security issue with our libraries or services please report it to secure@microsoft.com with as much detail as possible. Your submission may be eligible for a bounty through the Microsoft Bounty program. Please do not post security issues to GitHub Issues or any other public site. We will contact you shortly upon receiving the information. We encourage you to get notifications of when security incidents occur by visiting this page and subscribing to Security Advisory Alerts. ContributingAll code is licensed under the MIT license and we triage actively on GitHub. We enthusiastically welcome contributions and feedback. You can clone the repo and start contributing now. Quick Start
DownloadWe've made it easy for you to have multiple options to use this library in your iOS project: Option 1: Git SubmoduleIf your project is managed in a git repository you can include ADAL as a git submodule. First check the GitHub Releases Page for the latest release tag. Replace
We recommend only syncing to specific release tags to make sure you're at a known good point. We will not support versions of ADAL between release tags. Option 2: CocoapodsYou can use CocoaPods to remain up to date with ADAL within a specific major version. Include the following line in your podfile:
You then you can run either ADAL is using submodules, so if you're using a specific branch of ADAL in your Podfile, you need to enable submodules, e.g.
See CocoaPods for more information on setting up a PodFile Option 3: Source ZipTo download a copy of the source code, first make sure you're on the "master" branch and click "Clone or download" then "Download ZIP" in the upper right hand corner, or you can download it here This is not recommended, as it leaves no infrastructure in place for being able to easily update to the latest version. UsageCachingiOSKeychain SetupClick on your project in the Navigator pane in Xcode. Click on your application target and then the "Capabilities" tab. Scroll down to "Keychain Sharing" and flip the switch on. Add "com.microsoft.adalcache" to that list. Alternatively you can disable keychain sharing by setting the keychain sharing group to nil or your application's bundle id. [[ADALAuthenticationSettings sharedInstance] setDefaultKeychainGroup:nil]; Inspecting the CacheIf you need to inspect the cache in your app, you can do it through the ADKeychainTokenCache interface. macOSKeychain is not directly supported by ADAL on macOS. The default caching implementation will keep around tokens for the life time of the process, but they will not be persisted. If you wish to persist tokens you must implement the ADALTokenCacheDelegate and provide it on AuthenticationContext creation @protocol ADALTokenCacheDelegate <NSObject>
- (void)willAccessCache:(nonnull ADALTokenCache *)cache;
- (void)didAccessCache:(nonnull ADALTokenCache *)cache;
- (void)willWriteCache:(nonnull ADALTokenCache *)cache;
- (void)didWriteCache:(nonnull ADALTokenCache *)cache;
@end In this delegate you can call -serialize and -deserialize on the cache object to save or update the cache in the form of an NSData binary blob. Quick StartThe starting point for the API is in ADALAuthenticationContext.h header. ADALAuthenticationContext is the main class used for obtaining, caching and supplying access tokens. How to quickly get a token from the SDK:+ (void)getToken:(void (^)(NSString*))completionBlock;
{
ADALAuthenticationError *error = nil;
authContext = [ADALAuthenticationContext authenticationContextWithAuthority:@"https://login.microsoftonline.com/common"
error:&error];
[authContext acquireTokenWithResource:@"https://graph.windows.net"
clientId:@"<Your Client ID>" // Comes from App Portal
redirectUri:[NSURL URLWithString:@"<Your Redirect URI>"] // Comes from App Portal
completionBlock:^(ADALAuthenticationResult *result)
{
if (AD_SUCCEEDED != result.status){
// display error on the screen
[self showError:result.error.errorDetails];
}
else{
completionBlock(result.accessToken);
}
}];
} Adding the Token to the authHeader to access APIs: NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:yourAppURL];
NSString *authHeader = [NSString stringWithFormat:@"Bearer %@", accessToken];
[request addValue:authHeader forHTTPHeaderField:@"Authorization"];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:request
queue:queue
completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
// Process Response Here
}]; Brokered AuthenticationIf your app requires conditional access or certificate authentication (currently in preview) support, you must set up your AuthenticationContext and redirectURI to be able to talk to the Azure Authenticator app. Enable Broker Mode on Your ContextBroker is enabled on a per-authentication-context basis. You must set your credentials type if you wish ADAL to call to broker: /*! See the ADCredentialsType enumeration definition for details */
@property ADALCredentialsType credentialsType; The AD_CREDENTIALS_AUTO setting will allow ADAL to try to call out to the broker, AD_CREDENTIALS_EMBEDDED will prevent ADAL from calling to the broker. Registering a URL SchemeADAL uses URLs to invoke the broker and then return back to your app. To finish that round trip you need a URL scheme registered for your app. We recommend making the URL scheme fairly unique to minimize the chances of another app using the same URL scheme.
LSApplicationQueriesSchemesADAL uses –canOpenURL: to check if the broker is installed on the device. in iOS 9 Apple locked down what schemes an application can query for. You will need to add “msauth” and "msauthv3" to the LSApplicationQueriesSchemes section of your info.plist file. Note that "msauthv3" scheme is needed when compiling with Xcode 11+.
Redirect URIThis adds extra requirements on your redirect URI. Your redirect URI must be in the proper form.
This Redirect URI needs to be registered on the app portal as a valid redirect URI. Additionally a second "msauth" form needs to be registered to handle certificate authentication in Azure Authenticator.
iOS 13 supportIf you adopted UISceneDelegate, you must also add an ADAL callback into the This is needed so that ADAL can get a response from the Microsoft Authenticator application. For example: - (void)scene:(UIScene *)scene openURLContexts:(NSSet<UIOpenURLContext *> *)URLContexts
{
UIOpenURLContext *context = URLContexts.anyObject;
NSURL *url = context.URL;
NSString *sourceApplication = context.options.sourceApplication;
[ADALAuthenticationContext handleADALResponse:url sourceApplication:sourceApplication];
} If you're not using UISceneDelegate functionality yet, you can ignore this step. DiagnosticsLogsADAL relies heavily on logging to diagnose issues. It is highly recommended that you set an ADAL logging callback and provide a way for users to submit logs when they are having authentication issues. Logging CallbackYou can set a callback to capture ADAL logging and incorporate it in your own application's logging: /*!
The LogCallback block for the ADAL logger
@param logLevel The level of the log message
@param message A short log message describing the event that occurred, this string will not contain PII.
@param additionalInfo A longer message that may contain PII and other details relevant to the event.
@param errorCode An integer error code if the log message is an error.
@param userInfo A dictionary with other information relevant to the log message. The information varies,
for most error messages the error object will be in the "error" key.
*/
typedef void (^LogCallback)(ADAL_LOG_LEVEL logLevel,
NSString *message,
NSString *additionalInfo,
NSInteger errorCode,
NSDictionary *userInfo); Otherwise ADAL outputs to NSLog by default, which will print messages on the console. Example Log MessageThe message portion of ADAL iOS are in the format of ADALiOS [timestamp - correlation_id] message
Providing correlation IDs and timestamps are tremendously in tracking down issues. The only reliable place to retrieve them is from ADAL logging. Logging Levels
To set the logging level in your application call +[ADALLogger setLevel:] [ADALLogger setLevel:ADAL_LOG_LEVEL_INFO] Network TracesYou can use various tools to capture the HTTP traffic that ADAL generates. This is most useful if you are familiar with the OAuth protocol or if you need to provide diagnostic information to Microsoft or other support channels. Charles is the easiest HTTP tracing tool in OSX. Use the following links to setup it up
to correctly record ADAL network traffic. In order to be useful it is necessary to
configure Charles, to record unencrypted SSL traffic. NOTE: Traces generated in this way
may contain highly privileged information such as access tokens, usernames and passwords. ADALAuthenticationErrorADALAuthenticationErrors are provided in all callbacks in the ADALAuthenticationResult's error property when an error occurs. They can be used to have the application display more more informative errors to the user, however ADAL Error messages are not localized. All ADAuthenticationErrors are logged with the ADAL logger as well. ##Common problems Application, using the ADAL library crashes with the following exception: Solution: Make sure that you add the -ObjC flag to "Other Linker Flags" build setting
of the application. For more information, see Apple documentation for using static
libraries: Log ins are not persisting, Cache always returns empty Solution: Either add the "com.microsoft.adalcache" keychain sharing entitlement to your application, or disable keychain sharing by passing in your application's bundle id in ADAuthenticationSettings: [[ADALAuthenticationSettings sharedInstance] setDefaultKeychainGroup:nil]; ADAL keeps returning SSL errors in iOS 9 and later iOS 9 added App Transport Security (ATS). ATS restricts apps from accessing the internet unless they meet several security requirements including TLS 1.2 and SHA-256. It also prevents network traces that rely on self signed certs to crack SSL from working. Disabling ATS must be done in the Application's info.plist file, see documentation on the NSAppTransport info.plist key for more information. LicenseCopyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License (the "License"); We Value and Adhere to the Microsoft Open Source Code of ConductThis project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论