/// <summary> /// Generates the URI to redirect a user to when launching the Authorization Code Grant authentication flow. /// </summary> /// <returns>Authroization Code Authentication URI</returns> public System.Uri GenerateAuthorizationUri() { /// Construct a Query String var queryParams = new Utils.QueryParameterCollection { { "client_id", ClientId }, { "response_type", "code" }, { "resource", Resource }, { "redirect_uri", RedirectUri }, { "response_mode", ResponseMode }, { "state", State }, { "prompt", Prompt }, { "login_hint", LoginHint }, { "domain_hint", DomainHint } }; // Define required query params var requiredParams = new List <string>() { "client_id", "response_type", "redirect_uri" }; // Validate required values are included if (!queryParams.ValidateKeys(requiredParams)) { throw new MissingValueException($"One or more required parameters are missing or empty: {string.Join(",", requiredParams.ToArray())}"); } return(new Uri($"https://login.microsoftonline.com/{Tenant}/oauth2/authorize?{queryParams.ToQueryString()}")); }
/// <summary> /// Generates the URI to redirect a user to when launching the Authorization Code Grant authentication flow. /// </summary> /// <returns>Authroization Code Authentication URI</returns> public System.Uri GenerateAuthorizationUri() { /// Construct a Query String var queryParams = new Utils.QueryParameterCollection { { "client_id", ClientId }, { "response_type", "code" }, { "scope", Scope }, { "redirect_uri", RedirectUri }, { "response_mode", ResponseMode }, { "state", State }, { "prompt", Prompt }, { "login_hint", LoginHint }, { "domain_hint", DomainHint }, { "code_challenge_method", CodeChallengeMethod }, { "code_challenge", CodeChallenge } }; // Define required query params var requiredParams = new List <string>() { "client_id", "response_type", "scope" }; // If we have a code_challenge_method we need a code_challenge if (CodeChallengeMethod != null) { requiredParams.Add("code_challenge_method"); requiredParams.Add("code_challenge"); } // Validate required values are included if (!queryParams.ValidateKeys(requiredParams)) { throw new MissingValueException($"One or more required parameters are missing or empty: {string.Join(",", requiredParams.ToArray())}"); } // Ensure we have a valid ResponseMode if (!string.IsNullOrEmpty(Prompt) && Prompt != "consent" && Prompt != "login" && Prompt != "none") { throw new InvalidValueException($"Valid values for ResponseMode are 'login', 'none', and 'consent'. Current value: {Prompt}"); } return(new Uri($"https://login.microsoftonline.com/{Tenant}/oauth2/v2.0/authorize?{queryParams.ToQueryString()}")); }