public static async Task <string> GetAuthUrlAsync(ResumptionCookie resumptionCookie, string[] scopes) { var encodedCookie = UrlToken.Encode(resumptionCookie); Uri redirectUri = new Uri(AuthSettings.RedirectUrl); if (string.Equals(AuthSettings.Mode, "v2", StringComparison.OrdinalIgnoreCase)) { InMemoryTokenCacheMSAL tokenCache = new InMemoryTokenCacheMSAL(); Microsoft.Identity.Client.ConfidentialClientApplication client = new Microsoft.Identity.Client.ConfidentialClientApplication(AuthSettings.ClientId, redirectUri.ToString(), new Microsoft.Identity.Client.ClientCredential(AuthSettings.ClientSecret), tokenCache); //var uri = "https://login.microsoftonline.com/" + AuthSettings.Tenant + "/oauth2/v2.0/authorize?response_type=code" + // "&client_id=" + AuthSettings.ClientId + // "&client_secret=" + AuthSettings.ClientSecret + // "&redirect_uri=" + HttpUtility.UrlEncode(AuthSettings.RedirectUrl) + // "&scope=" + HttpUtility.UrlEncode("openid profile " + string.Join(" ", scopes)) + // "&state=" + encodedCookie; var uri = await client.GetAuthorizationRequestUrlAsync( scopes, null, "state=" + encodedCookie); return(uri.ToString()); } else if (string.Equals(AuthSettings.Mode, "b2c", StringComparison.OrdinalIgnoreCase)) { return(null); } return(null); }
private static string BuildExtraParameters(ResumptionCookie resumptionCookie) { var encodedCookie = UrlToken.Encode(resumptionCookie); //var queryString = HttpUtility.ParseQueryString(string.Empty); //queryString["userId"] = resumptionCookie.Address.UserId; //queryString["botId"] = resumptionCookie.Address.BotId; //queryString["conversationId"] = resumptionCookie.Address.ConversationId; //queryString["serviceUrl"] = resumptionCookie.Address.ServiceUrl; //queryString["channelId"] = resumptionCookie.Address.ChannelId; //queryString["locale"] = resumptionCookie.Locale ?? "en"; //return TokenEncoder(queryString.ToString()); return(encodedCookie); }
public static async Task <string> GetAuthUrlAsync(ResumptionCookie resumptionCookie, string resourceId) { var encodedCookie = UrlToken.Encode(resumptionCookie); Uri redirectUri = new Uri(AuthSettings.RedirectUrl); Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext context = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(AuthSettings.EndpointUrl + "/" + AuthSettings.Tenant); var uri = await context.GetAuthorizationRequestUrlAsync( resourceId, AuthSettings.ClientId, redirectUri, Microsoft.IdentityModel.Clients.ActiveDirectory.UserIdentifier.AnyUser, "state=" + encodedCookie); return(uri.ToString()); }
public static async Task <string> GetAuthUrlAsync(ResumptionCookie resumptionCookie) { var encodedCookie = UrlToken.Encode(resumptionCookie); Uri redirectUri = new Uri(AuthSettings.RedirectUrl); if (string.Equals(AuthSettings.Mode, "v1", StringComparison.OrdinalIgnoreCase)) { Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext context = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(AuthSettings.EndpointUrl + "/" + AuthSettings.Tenant); var uri = await context.GetAuthorizationRequestUrlAsync( AuthSettings.ResourceId, AuthSettings.ClientId, redirectUri, Microsoft.IdentityModel.Clients.ActiveDirectory.UserIdentifier.AnyUser, "state=" + encodedCookie); return(uri.ToString()); } else if (string.Equals(AuthSettings.Mode, "v2", StringComparison.OrdinalIgnoreCase)) { InMemoryTokenCacheMSAL tokenCache = new InMemoryTokenCacheMSAL(); Microsoft.Identity.Client.ConfidentialClientApplication client = new Microsoft.Identity.Client.ConfidentialClientApplication(AuthSettings.ClientId, redirectUri.ToString(), new Microsoft.Identity.Client.ClientCredential(AuthSettings.ClientSecret), tokenCache); var uri = await client.GetAuthorizationRequestUrlAsync( AuthSettings.Scopes, null, "state=" + encodedCookie); //, // null // clientId.Value, // redirectUri, // Microsoft.Experimental.IdentityModel.Clients.ActiveDirectory.UserIdentifier.AnyUser, // "state=" + encodedCookie); return(uri.ToString()); } else if (string.Equals(AuthSettings.Mode, "b2c", StringComparison.OrdinalIgnoreCase)) { return(null); } return(null); }