Giter VIP home page Giter VIP logo

active-directory-ios's Introduction

Services platforms author level client service endpoint
active-directory
iOS
brandwe
100
iOS Mobile App
Microsoft Graph
AAD V1

ADAL Swift Microsoft Graph API Sample

Getting Started Library API Reference Support

There's a newer version of this sample! Check it out: https://github.com/azure-samples/ms-identity-ios-swift-native

This newer sample takes advantage of the Microsoft identity platform (formerly Azure AD v2.0).

While still in public preview, every component is supported in production environments.

The ADAL Objective C library gives your app the ability to begin using the Microsoft Azure Cloud by supporting Microsoft Azure Active Directory accounts using industry standard OAuth2 and OpenID Connect. This sample demonstrates all the normal lifecycles your application should experience, including:

  • Get a token for the Microsoft Graph
  • Refresh a token
  • Call the Microsoft Graph
  • Sign out the user

Scenario

This app can be used for all Azure AD accounts. It demonstrates how a developer can build apps to connect with enterprise users and access their Azure + O365 data via the Microsoft Graph. During the auth flow, end users will be required to sign in and consent to the permissions of the application, and in some cases may require an admin to consent to the app. The majority of the logic in this sample shows how to auth an end user and make a basic call to the Microsoft Graph.

Topology

Steps to Run

Register & Configure your app

You will need to have a native client application registered with Microsoft using the Azure portal.

  1. Getting to app registration

  2. Create the app

    • Click New registration.
    • Enter an app name in the Name field.
    • In Supported account types, select Accounts in any origanizational directory and personal Microsoft accounts.
    • In Redirect URI (optional), select Public client (mobile & desktop) and enter urn:ietf:wg:oauth:2.0:oobas the URI.
  3. Configure Microsoft Graph API Access

    • Select API Permissions
    • Select Add a permission, and then select Microsoft Graph.
    • Select Delegated permissions and select the permissions offline_access, openid, and profile. We'll also need User.Read, but this is selected by default for us already.
    • Hit Add permissions to save.
  4. Congrats! Your app is successfully configured. In the next section, you'll need:

    • Application ID
    • Redirect URI
    • Entitlements
      • Is required for building your own Xcode project

Get the code

  1. Download Cocoapods (if you don't already have it)

CocoaPods is the dependency manager for Swift and Objective-C Cocoa projects. It has thousands of libraries and can help you scale your projects elegantly. To install on OS X 10.9 and greater simply run the following command in your terminal:

$ sudo gem install cocoapods

  1. Build the sample and pull down ADAL for iOS automatically

Run the following command in your terminal:

$ pod install

This will download and build ADAL for iOS for you and configure your Microsoft Tasks.xcodeproj to use the correct dependencies.

Step 4: Run the application in Xcode

This will download and build ADAL for iOS for you and configure your QuickStart.xcodeproj to use the correct dependencies.

You should see the following output:

$ pod install
Analyzing dependencies
Downloading dependencies
Installing ADAL (2.5.2)
Generating Pods project
Integrating client project

[!] Please close any current Xcode sessions and use `QuickStart.xcworkspace` for this project from now on.
Sending stats
Pod installation complete! There is 1 dependency from the Podfile and 1 total pod installed.
  1. Run the application in Xcode

Launch XCode and load the QuickStart.xcworkspace file. The application will run in an emulator as soon as it is loaded.

  1. Configure the ViewController.swift file with your app information

You will need to configure your application to work with the Azure AD tenant you've created.

  • In the QuickStart project, open the file ViewController.swift. Replace the values of the elements in the section to reflect the values you input into the Azure Portal. Your code will reference these values whenever it uses ADAL.
    • The kClientID is the clientId of your application you copied from the portal.
    • The kRedirectUri is the redirect url you registered in the portal.

If you are adding ADAL to an existing Xcode project or you've created a new one on your own, you'll also need to enable Keychain Sharing.

  • In the Signing & capabilities tap, add Keychain Sharing if you don't have one
  • Add com.microsoft.adalcache into Keychain Groups

If your app supports Brokered Authentication, you will need to update the CFBundleURLSchemes name

  • In the QuickStart project, open the file Info.plist. replace the CFBundleURLSchemes with your scheme name
<key>CFBundleURLTypes</key>
    <array>
        <dict>
            <key>CFBundleTypeRole</key>
            <string>Editor</string>
            <key>CFBundleURLName</key>
            <string>$(PRODUCT_BUNDLE_IDENTIFIER)</string>
            <key>CFBundleURLSchemes</key>
            <array>
                 <string>adal-sample-app</string>
            </array>
            </dict>
    </array>

Important Info

  1. Checkout the ADAL Objective C Wiki for more info on the library mechanics and how to configure new scenarios and capabilities.
  2. In Native scenarios, the app will use an embedded Webview and will not leave the app. The Redirect URI can be arbitrary.
  3. Find any problems or have requests? Feel free to create an issue or post on Stackoverflow with tag azure-active-directory.

Feedback, Community Help, and Support

We use Stack Overflow 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.

If you find and bug or have a feature request, please raise the issue on GitHub Issues.

To provide a recommendation, visit our User Voice page.

Contribute

We enthusiastically welcome contributions and feedback. You can clone the repo and start contributing now. Read our Contribution Guide for more information.

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

Security Library

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 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.

Security Reporting

If you find a security issue with our libraries or services please report it to [email protected] 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.

active-directory-ios's People

Contributors

acomsmpbot avatar allisonam avatar brandwe avatar chrisamelinckx avatar danieldobalian avatar dstrockis avatar gsacavdm avatar jmprieur avatar k-rush avatar kaisong1990 avatar nickvdheuvel avatar oldalton avatar parakhj avatar sri- avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

active-directory-ios's Issues

Need updated sample for ADAL 2.6.0

Want to use new ADAL 2.6.0 and should migrate ADLogger.setLogCallBack. Could you deliver please an updated sample code version while your current sample uses still ADALiOS (1.2.9). Thanks and cheers!

Is it required to use NSURLConnection for calling web API ?

Hi,

I wanted to have clarity about the web API calls using native iOS app. In the demo's provided API calls are made using NSURLConnection which is I believe now deprecated or replaced by NSURLSession.
Is it compulsory to use NSURLConnection for the SDK to work correctly ?

Thanks,
Umar

ERROR 3840: The data couldn’t be read because it isn’t in the correct format.

I'm able to Sign Up but when I try to Sign In I get this error:

2016-02-24 17:48:30.047 Microsoft Tasks for Consumers[8167:232019] -[ADAuthenticationBroker webAuthenticationDidCompleteWithURL:][408][main]
2016-02-24 17:48:31.275 Microsoft Tasks for Consumers[8167:232077] ADALiOS [2016-02-24 20:48:31 - 00000000-0000-0000-0000-000000000000] ERROR: JSON deserialization. Additional Information: Error: Error Domain=NSCocoaErrorDomain Code=3840 "JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set.}. Body text: 'Bad Request'. HTTPS Code: 400. Response correlation id: (null). ErrorCode: 3840.
2016-02-24 17:48:31.287 Microsoft Tasks for Consumers[8167:232077] ADALiOS [2016-02-24 20:48:31 - 00000000-0000-0000-0000-000000000000] ERROR: Error raised: 3840. Additional Information: Domain: NSCocoaErrorDomain Details: The data couldn’t be read because it isn’t in the correct format.. ErrorCode: 3840.

captura de pantalla 2016-02-24 a las 17 50 17

Any clue?

Does not run out of the box

The recent update to the Podfile in commit 82b31f6 changed the name of the pod library target from "libPods" to "libPods-Microsoft Tasks".

However, the Microsoft Tasks project still references the pods library with the old name.

The linker (ld) is failing because of this.

I had to remove the invalid reference to get the app to run.

Build errors regarding CocoaPods

Received build errors regarding CocoaPods
Should we update the documentation to clearly describe the steps and pre-requisites?

Microsoft Tasks Group
/NativeClient-iOS/Microsoft Tasks.xcodeproj
NativeClient-iOS/Microsoft Tasks.xcodeproj The file “Pods.xcconfig” couldn’t be opened because there is no such file. (/NativeClient-iOS/Pods/Pods.xcconfig)
The file “Pods.xcconfig” couldn’t be opened because there is no such file. (/NativeClient-iOS/Pods/Pods.xcconfig)
Diff: /../Podfile.lock: No such file or directory
Diff: /Manifest.lock: No such file or directory
The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.

Podfile uses unsupported `link_with` and deprecated 'xcodeproj` directives

Fresh checkout and running pod install gives me the following:

➜  active-directory-ios git:(master) pod install

[!] Invalid `Podfile` file: [!] The specification of `link_with` in the Podfile is now unsupported, please use target blocks instead..

 #  from /Users/duncan/Code/src/github/Azure-Samples/active-directory-ios/Podfile:2
 #  -------------------------------------------
 #  source 'https://github.com/CocoaPods/Specs.git'
 >  link_with ['Microsoft Tasks', 'Microsoft TasksTests']
 #  xcodeproj 'Microsoft Tasks'
 #  -------------------------------------------

A bunch of build errors in BVTestMainViewController.m

Hey folks,
Got latest sources, but found lots of builds errors.
Can you please fix or recommend a last known good release or commit id?

azure-activedirectory-library-for-ios/Samples/MyTestiOSApp/MyTestiOSApp/BVTestMainViewController.m:136:18: Property 'parentController' not found on object of type 'ADAuthenticationContext *'

azure-activedirectory-library-for-ios/Samples/MyTestiOSApp/MyTestiOSApp/BVTestMainViewController.m:179:13: Property 'parentController' not found on object of type 'ADAuthenticationContext *'

azure-activedirectory-library-for-ios/Samples/MyTestiOSApp/MyTestiOSApp/BVTestMainViewController.m:181:14: No visible @interface for 'ADAuthenticationContext' declares the selector 'acquireTokenSilentWithResource:clientId:redirectUri:userId:completionBlock:'

azure-activedirectory-library-for-ios/Samples/MyTestiOSApp/MyTestiOSApp/BVTestMainViewController.m:196:32: No known instance method for selector 'allItemsWithError:'

azure-activedirectory-library-for-ios/Samples/MyTestiOSApp/MyTestiOSApp/BVTestMainViewController.m:205:16: No known instance method for selector 'removeAllWithError:'

azure-activedirectory-library-for-ios/Samples/MyTestiOSApp/MyTestiOSApp/BVTestMainViewController.m:236:29: No known instance method for selector 'allItemsWithError:'

azure-activedirectory-library-for-ios/Samples/MyTestiOSApp/MyTestiOSApp/BVTestMainViewController.m:288:42: No known instance method for selector 'getItemWithKey:userId:error:'

azure-activedirectory-library-for-ios/Samples/MyTestiOSApp/MyTestiOSApp/BVTestMainViewController.m:316:29: No known instance method for selector 'allItemsWithError:'

Run custom shell script 'Copy Pods Resources'

I have read and followed the instructions by "README.md". But when I run the pod install, I got this problem. Please help me on this.

/Users/nyeinei/Library/Developer/Xcode/DerivedData/Microsoft_Tasks-ecjhvycfemjqqccjzygmwljipuyc/Build/Intermediates.noindex/Microsoft Tasks.build/Debug-iphonesimulator/Microsoft Tasks.build/Script-2E16D7D83C534279873FC06F.sh: line 2: /Users/nyeinei/Downloads/active-directory-ios-master/Pods/Target Support Files/Pods/Pods-resources.sh: No such file or directory

Running the app results in ADALiOS: ERROR: Error raised: 18

The app is building correctly but running it results in the below error.

2014-07-21 11:33:39.854 Microsoft Tasks[2370:60b] NSMainNibFile and UIMainStoryboardFile are both set. NSMainNibFile ignored.
2014-07-21 11:33:39.928 Microsoft Tasks[2370:60b] ADALiOS: ERROR: Error raised: 18. Additional Information: Domain: ADAuthenticationErrorDomain ProtocolCode:(null) Details:The required resource bundle could not be loaded. Please read the ADALiOS readme on how to build your application with ADAL provided authentication UI resources.. ErrorCode: 18.
2014-07-21 11:33:39.929 Microsoft Tasks[2370:60b] ADALiOS: ERROR: Error raised: 18. Additional Information: Domain: ADAuthenticationErrorDomain ProtocolCode:(null) Details:The required resource bundle could not be loaded. Please read the ADALiOS readme on how to build your application with ADAL provided authentication UI resources.. ErrorCode: 18.

git clone [email protected]:AzureADSamples/NativeClient-iOS.git does not work

git clone [email protected]:AzureADSamples/NativeClient-iOS.git
I can only clone using git clone https://github.com/AzureADSamples/NativeClient-iOS

Logs
$ git clone [email protected]:AzureADSamples/NativeClient-iOS.git
Cloning into 'NativeClient-iOS'...
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

$ git clone https://github.com/AzureADSamples/NativeClient-iOS
Cloning into 'NativeClient-iOS'...
remote: Counting objects: 89, done.
remote: Total 89 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (89/89), done.
Checking connectivity... done.

could not get access token, told not to retry

I copied the VC code in the demo project to my VC and copied the UI in storyboard, setup entitlement as well.

My issue is "Couldn't get access token and we were told not to retry." the demo app connects to my azure bot with the correct kClientID string and kRedirectUri string

Are there other requirements to get the login to work in another Xcode project?

gives linker error in xcode 8.3.2

Hello,

1)I tries to download the project
2) unzip the project (not yet open in the xcode)
3)Open terminal
4) cd to my project path
5) $ sudo gem install cocoapods
6) $ pod install
I made sure the pod install properly.No error shown in the terminal
7)Open the project "Microsoft Tasks.xcworkspace" in xcode8.3.2
8)build the project
It gives me linker error

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Please help me is there any step i am doing wrong ?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.