This repository was archived by the owner on Aug 29, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Add client id and tenant id options to the login command #21
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
0ef544a
Add client id and tenant id options to the login command
calebkiage 1218788
Update code owners
calebkiage 2129cc9
Update src/Microsoft.Graph.Cli.Core/IO/AuthenticationCacheUtility.cs
calebkiage 1aed0b7
Store cached authentication identifiers as json
calebkiage 770944a
Merge branch 'feat/allow_setting_tenant_id_on_login' of https://githu…
calebkiage df9a000
Allow nulls for client and tenant ids
calebkiage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| * @calebkiage @baywet @zengin @MichaelMainer @andrueastman @peombwa @jobala @samwelkanda | ||
| * @calebkiage @baywet @zengin @MichaelMainer @andrueastman @peombwa @samwelkanda |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/Microsoft.Graph.Cli.Core/Configuration/ConfigurationRoot.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| namespace Microsoft.Graph.Cli.Core.Configuration; | ||
|
|
||
| public class ConfigurationRoot { | ||
| public AuthenticationOptions AuthenticationOptions { get; set; } = new AuthenticationOptions(); | ||
| } |
63 changes: 63 additions & 0 deletions
63
src/Microsoft.Graph.Cli.Core/IO/AuthenticationCacheUtility.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| using System.Text; | ||
| using System.Text.Json; | ||
| using Microsoft.Graph.Cli.Core.Configuration; | ||
| using Microsoft.Graph.Cli.Core.Utils; | ||
|
|
||
| namespace Microsoft.Graph.Cli.Core.IO; | ||
|
|
||
| public class AuthenticationCacheUtility : IAuthenticationCacheUtility { | ||
| private readonly IPathUtility pathUtility; | ||
|
|
||
| public AuthenticationCacheUtility(IPathUtility pathUtility) | ||
| { | ||
| this.pathUtility = pathUtility; | ||
| } | ||
|
|
||
| public string GetAuthenticationCacheFilePath() | ||
| { | ||
| return Path.Join(pathUtility.GetApplicationDataDirectory(), Constants.AuthenticationIdCachePath); | ||
| } | ||
|
|
||
| public async Task<AuthenticationOptions> ReadAuthenticationIdentifiersAsync(CancellationToken cancellationToken = default) | ||
| { | ||
| cancellationToken.ThrowIfCancellationRequested(); | ||
| var path = this.GetAuthenticationCacheFilePath(); | ||
| if (!File.Exists(path)) { | ||
| throw new FileNotFoundException(); | ||
| } | ||
|
|
||
| using var fileStream = File.OpenRead(path); | ||
| var configRoot = await JsonSerializer.DeserializeAsync<Configuration.ConfigurationRoot>(fileStream, cancellationToken: cancellationToken); | ||
| if (configRoot?.AuthenticationOptions is null) throw new AuthenticationIdentifierException("Cannot find cached authentication identifiers."); | ||
|
|
||
| return configRoot.AuthenticationOptions; | ||
| } | ||
|
|
||
| public async Task SaveAuthenticationIdentifiersAsync(string? clientId, string? tenantId, CancellationToken cancellationToken = default) { | ||
| cancellationToken.ThrowIfCancellationRequested(); | ||
| var path = this.GetAuthenticationCacheFilePath(); | ||
| var configuration = new Configuration.ConfigurationRoot { | ||
| AuthenticationOptions = new AuthenticationOptions { | ||
| ClientId = clientId, | ||
| TenantId = tenantId | ||
| } | ||
| }; | ||
| using FileStream fileStream = File.OpenWrite(path); | ||
| await JsonSerializer.SerializeAsync(fileStream, configuration, cancellationToken: cancellationToken); | ||
| } | ||
|
|
||
| public class AuthenticationIdentifierException : Exception | ||
| { | ||
| public AuthenticationIdentifierException() | ||
| { | ||
| } | ||
|
|
||
| public AuthenticationIdentifierException(string? message) : base(message) | ||
| { | ||
| } | ||
|
|
||
| public AuthenticationIdentifierException(string? message, Exception? innerException) : base(message, innerException) | ||
| { | ||
| } | ||
| } | ||
| } | ||
11 changes: 11 additions & 0 deletions
11
src/Microsoft.Graph.Cli.Core/IO/IAuthenticationCacheUtility.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| using Microsoft.Graph.Cli.Core.Configuration; | ||
|
|
||
| namespace Microsoft.Graph.Cli.Core.IO; | ||
|
|
||
| public interface IAuthenticationCacheUtility { | ||
| string GetAuthenticationCacheFilePath(); | ||
|
|
||
| Task SaveAuthenticationIdentifiersAsync(string? clientId, string? tenantId, CancellationToken cancellationToken = default(CancellationToken)); | ||
|
|
||
| Task<AuthenticationOptions> ReadAuthenticationIdentifiersAsync(CancellationToken cancellationToken = default(CancellationToken)); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.