0

So far i have this.

        public static async Task<OutlookServicesClient> CreateOutlookClientAsync(string capability)
        {
            try
            {

                string authority = CommonAuthority;

                // Create an AuthenticationContext using this authority.
                _authenticationContext = new AuthenticationContext(authority);

                //See the Discovery Service Sample (https://github.com/OfficeDev/Office365-Discovery-Service-Sample)
                //for an approach that improves performance by storing the discovery service information in a cache.
                DiscoveryClient discoveryClient = new DiscoveryClient(
                    async () => await GetTokenHelperAsync(_authenticationContext, DiscoveryResourceId));

                // Get the specified capability ("Contacts").
                CapabilityDiscoveryResult result =
                    await discoveryClient.DiscoverCapabilityAsync(capability);
                var client = new OutlookServicesClient(
                    result.ServiceEndpointUri,
                    async () =>
                        await GetTokenHelperAsync(_authenticationContext, result.ServiceResourceId));
                return client;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                if (_authenticationContext != null && _authenticationContext.TokenCache != null)
                    _authenticationContext.TokenCache.Clear();
                return null;
            }
        }

    }

 private static async Task<string> GetTokenHelperAsync(AuthenticationContext context, string resourceId)
        {
            string accessToken = null;
            AuthenticationResult result = null;
            string myId = WebConfigurationManager.AppSettings["ida:ClientID"];
            string myKey = WebConfigurationManager.AppSettings["ida:Password"];
            ClientCredential client = new ClientCredential(myId,myKey);
            
            result = await context.AcquireTokenAsync(resourceId, client);
            //result =context.AcquireToken(resourceId, ClientID,_returnUri);
            accessToken = result.AccessToken;


            return accessToken;
        }

When i get to result one of two things happen if i user AcquireTokenAsync i get an error stating Application with identifier XXXX was not found in directory api.office.com otherwise if i run AcquireToken i get the login modal to pop but an error occurs indicating the request must contain client_secret .

I have no idea how to resolve this issue i suspect it may have something to do with the actual app configuration i have tried both creating my own app in Azure AD and using VS Connected Service, Has Anyone Else ran into a similar issues?

Jason Johnston
  • 17,194
  • 2
  • 20
  • 34
Frank
  • 5
  • 2

1 Answers1

1

Based on the errors you're seeing, there seems to be an issue with how your app is registered. The first error usually happens when the app is not marked as multi-tenant, and you login to the app with a tenant other than the one where the app is registered.

The second error is odd. Client secret is what you're reading out of the ida:Password element and passing in the ClientCredential object.

I just put a .NET tutorial up yesterday that walks through setting this stuff up. Take a look and see if that helps get you unblocked.

Jason Johnston
  • 17,194
  • 2
  • 20
  • 34
  • Thanks Jason. I used your tutorial to get an auth token but now i get a null reference exception coming from mscorlib.dll – Frank May 01 '15 at 15:34
  • Thanks Jason for the tutorial! I got it working with the O365 Unified API :) Now I have it integrated with my MVC application finally! – Vardhaman Deshpande May 03 '15 at 23:32