I’m attempting to use Microsoft’s Graph API to access calendar information on an application I’m building, using C# and .NET. As I understand it, you must set the TenantId
while setting up authentication to “common”, as this will allow either Microsoft emails or personal emails to use the app registration.
It was working as expected on my personal email I was using for development, but then it stopped allowing personal emails:
I’m not certain if this is because of changes I made to my code or something on the back-end changed, but I can’t seem to fix this issue.
Here’s the pertinent code:
private const string TENANT_ID = "common";
private const string CLIENT_ID = "<CLIENT_ID>";
private static readonly FileInfo s_authPath = new FileInfo("./csOutlookStorage");
private static readonly string s_tokenCacheName = "OwsAuthToken";
private GraphServiceClient _client;
public bool AccountLinked => s_authPath.Exists;
public async Task InitializeAsync(CancellationToken token = default)
{
var credentialOptions = new InteractiveBrowserCredentialOptions()
{
TenantId = TENANT_ID,
ClientId = CLIENT_ID,
TokenCachePersistenceOptions = new TokenCachePersistenceOptions() { Name = s_tokenCacheName },
RedirectUri = new Uri("http://localhost:3006")
};
InteractiveBrowserCredential credential;
if(!AccountLinked)
{
credential = new InteractiveBrowserCredential(credentialOptions);
var authRecord = await credential.AuthenticateAsync(token);
using (var authRecordStream = s_authPath.Open(FileMode.Create))
{
await authRecord.SerializeAsync(authRecordStream);
}
}
...
I’d appreciate any help in this matter. Thanks very much