Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/Authentication/Authentication/Cmdlets/ConnectMgGraph.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ public class ConnectMgGraph : PSCmdlet, IModuleAssemblyInitializer, IModuleAssem
[Parameter(ParameterSetName = Constants.EnvironmentVariableParameterSet, Mandatory = false, HelpMessage = HelpMessages.EnvironmentVariable)]
public SwitchParameter EnvironmentVariable { get; set; }

[Parameter(Mandatory = false, HelpMessage = HelpMessages.NoWelcome)]
public SwitchParameter NoWelcome { get; set; }

[Parameter(Mandatory = false, DontShow = true, HelpMessage = "Wait for .NET debugger to attach")]
public SwitchParameter Break { get; set; }

Expand Down Expand Up @@ -248,7 +251,9 @@ private async Task ProcessRecordAsync()
await AuthenticationHelpers.LogoutAsync();
throw;
}
WriteObject("Welcome To Microsoft Graph!");

if (!NoWelcome.IsPresent)
WriteObject(GetWelcomeMessage(authContext.ClientId, authContext.AuthType.ToString()));
}
}
protected override void StopProcessing()
Expand All @@ -257,6 +262,18 @@ protected override void StopProcessing()
base.StopProcessing();
}

private static string GetWelcomeMessage(string clientId, string authType)
{
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.AppendLine($"Welcome to Microsoft Graph!{System.Environment.NewLine}");
stringBuilder.AppendLine($"Connected via {authType.ToLower()} access using {clientId}");
stringBuilder.AppendLine($"Readme: {Constants.SdkReadmeLink}");
stringBuilder.AppendLine($"SDK Docs: {Constants.SdkDocsLink}");
stringBuilder.AppendLine($"API Docs: {Constants.ApiDocsLink}{System.Environment.NewLine}");
stringBuilder.AppendLine($"NOTE: You can use the -NoWelcome parameter to suppress this message.");
return stringBuilder.ToString();
}

/// <summary>
/// Processes user provided scopes by removing whitespace and splitting comma separated scopes.
/// </summary>
Expand Down
4 changes: 4 additions & 0 deletions src/Authentication/Authentication/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public static class Constants
internal const int DEFAULT_RETRY_DELAY = 3;
internal const int DEFAULT_MAX_RETRY = 3;
internal static readonly string GraphOptionsFilePath = Path.Combine(Core.Constants.GraphDirectoryPath, "mg.graphoptions.json");
internal static readonly string SdkReadmeLink = "https://aka.ms/graph/sdk/powershell";
internal static readonly string SdkDocsLink = "https://aka.ms/graph/sdk/powershell/docs";
internal static readonly string ApiDocsLink = "https://aka.ms/graph/docs";

public static class HelpMessages
{
Expand All @@ -40,6 +43,7 @@ public static class HelpMessages
public const string Environment = "The name of the national cloud environment to connect to. By default global cloud is used.";
public const string UseDeviceCode = "Use device code authentication instead of a browser control.";
public const string ClientTimeout = "Sets the HTTP client timeout in seconds.";
public const string NoWelcome = "Hides the welcome message.";
public const string Identity = "Login using a Managed Identity.";
public const string EnvironmentVariable = "Allows for authentication using environment variables configured on the host machine. See https://github.com/Azure/azure-sdk-for-net/tree/main/sdk/identity/Azure.Identity#environment-variables.";
public const string ManagedIdentityClientId = "The client id to authenticate for a user assigned managed identity. For more information on user assigned managed identities see: https://docs.microsoft.com/azure/active-directory/managed-identities-azure-resources/overview#how-a-user-assigned-managed-identity-works-with-an-azure-vmId. To use the SystemAssigned identity, leave this field blank.";
Expand Down