Hi,
i'm searching this for hours now, and nothing is working. Only broken Nuget Packages, Android examples that should work on iOS, ...
But nothing that shows the OAuth authentication flow and a simple query to Office 365... Is it really that difficult?
Best Regards
Jörg
Answers
Hi! any luck with your search?
Any good article to read please?
Months later, I'm in the exact same position. Extremely disappointing.
Did anyone get anywhere with this?
This is covered party completely in the Microsoft documentation: https://msdn.microsoft.com/en-us/office/office365/howto/common-app-authentication-tasks
We found several articles that dance around the topic.
Add Storage to Your Apps with Office 365
https://blog.xamarin.com/add-storage-to-your-apps-with-office-365/
Put Some Office 365 in Your Apps
http://forums.xamarin.com/discussion/21367/put-some-office-365-in-your-apps
** Office 365 Client App using Xamarin.Android and Office 365 Client Libraries**
https://github.com/mayur-tendulkar/O365Client
But what were looking for is an example of how to get an OAuth2 token for an IOS application.
Also see that the Xamarin.Auth component works with OAuth2, but how to connect the dots is the question.
We got this sample working
Office 365 Connect app for iOS
https://github.com/OfficeDev/O365-iOS-Connect
But its in Objective-C
At the bottom of that github page they have a great collection of info
Have you seen this sample found in this blog post? The information is for authenticating with Azure Active Directory and the sample calls the Azure AD Graph API, but Office 365 uses the same authentication flow.
Thank you @DaveHunt. I think you found it.
Your welcome!
Based on this blog post cloudidentity.com/blog/2015/07/22/using-adal-3-x-with-xamarin-forms/
I was able to build an app that connects from a xamarin ios application (not using Forms). The way i did it was to modify the sample like this
`public partial class ViewController : UIViewController
{
public ViewController(IntPtr handle)
: base(handle)
{
}
I also had to modify the Info.plist file to include the following entries
<key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict> <key>LSApplicationQueriesSchemes</key> <array> <string>msauth</string> </array>
However, after all this is done and the app runs, i eventually get an error on the console log and the authentication page is not displayed.
2016-03-10 13:41:11.340 EwsOAuthTest[54209:9397460] -canOpenURL: failed for URL: "msauth://" - error: "(null)"
I've been unable to fix this, it looks like the webview doesn't support loading urls with the msauth:// scheme?
Is worth noting that when i run the same code from a windows forms desktop application everything works as expected and i can get the authentication dialog and then get the token back. So this is an ios only issue.
Any help will be greatly appreciated.
Below a sample Windows Forms desktop app which is able to authenticate correctly
`class EwsAuthManager
{
public async void GetToken()
{
var token = "";
try
{
var authority = "https://login.microsoftonline.com/common";
var authContext = new AuthenticationContext(authority);
`public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
I finally got it working. I have attached a sample app that does a basic login and gets back a token.
Once you get the login dialog the first time and enter your credentials the dialog won't be displayed again if you go through the same code, instead it just silently returns the same token that was generated on the first call.
Attached is my sample code in case anyone is interested