title: How can I use the Azure AD without single-sign-on
body: <p>Basically I'm implementing an SSO for an employee portal that I'm making for us, but I'd also like to be able to access the graph API (At the least, the AzureAD REST API items, like adding/removing/getting users information) without having to be signed in through an SSO.</p>
  
  <p>This way, I can use what I'm thinking to be some kind of API key/secret sort of setup and schedule cron jobs that interact with the AD in some way. Technically I could signin and set my account to be the one running this, but that seems kind of hacky and unreliable (as in, if something happens to my account, password expires, changes, etc... then the refresh token will no longer be valid and I'll have to sign in again and the task could be temporarily broken.)</p>
  
  <p>I could have sworn I've seen documentation for this somewhere when I was looking into implementing this a few months ago, but I can't for the life of me find it now.</p>
  
  <p>Really hope this isn't a duplicate, I just can't think of wording to search for that doesn't keep coming up with SSO-based API information.</p>
  
  <p><strong>Update - Alright, it looks like I figured this out (with the help of Shaun Luttin's answer posted below: <a href="https://stackoverflow.com/a/32618417/3721165">https://stackoverflow.com/a/32618417/3721165</a> [link for convenience])</strong></p>
  
  <p>So, all of the info Shaun brought together was really helpful. Initially the docs were fairly confusing due to how they word things, as well as the complexity of some of their examples. But once I got to digging through some of the examples, plus some of the info Shaun provided, and some experimenting/research on my own, I was able to come up with this (basic demo/concept):</p>
  
  <pre><code>using System;
  using System.Globalization;
  using System.Threading.Tasks;
  
  using Microsoft.IdentityModel.Clients.ActiveDirectory;
  using Microsoft.Azure.ActiveDirectory.GraphClient;
  
  
  namespace AzureADGraphApi
  {
      class Program
      {
          private static string tenant = "...tenant id...";
          private static string clientid = "...client id...";
          private static string appkey = "...app key...";
          private static string aadinstance = "https://login.microsoftonline.com/{0}";
          private static string graphResourceUrl = "https://graph.windows.net";
  
          static void Main(string[] args)
          {
              Uri serviceRoot = new Uri(graphResourceUrl + "/" + tenant);
              ActiveDirectoryClient adc = new ActiveDirectoryClient(serviceRoot, async () =&gt; await GetToken());
  
              IPagedCollection&lt;IUser&gt; Users = adc.Users.ExecuteAsync().Result;
  
              bool pagesLeft = false;
              do
              {
                  foreach (IUser user in Users.CurrentPage)
                  {
                      Console.WriteLine(user.DisplayName);
                  }
                  pagesLeft = Users.MorePagesAvailable;
                  Users = Users.GetNextPageAsync().Result;
                  Console.WriteLine("--- Page Break ---");
              } while (pagesLeft);
              Console.ReadLine();
          }
  
          private static async Task&lt;string&gt; GetToken()
          {
              AuthenticationContext authContext = new AuthenticationContext(String.Format(CultureInfo.InvariantCulture, aadinstance, tenant));
              AuthenticationResult result = authContext.AcquireToken(graphResourceUrl, new ClientCredential(clientid, appkey));
              return result.AccessToken;
          }
      }
  }
  </code></pre>
  
  <p>I found through further research that in order to use the Graph API the way I'm intending, you have to provide the graph resource URL (<a href="https://graph.windows.net" rel="nofollow noreferrer">https://graph.windows.net</a>) to the AquireToken method, instead of your app ID/URL.</p>
  
  <p>So, I'm accepting Shaun's answer, but I also wanted to give my working result of that answer.</p>
  
  <p>Thanks for the help, guys!</p>