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(ConversationReference conversationReference, string resourceId)
        {
            var extraParameters = BuildExtraParameters(conversationReference);

            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={extraParameters}");

            return(uri.ToString());
        }
Example #3
0
        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);
        }
Example #4
0
        public static async Task <string> GetAuthUrlAsync(ResumptionCookie resumptionCookie, string resourceId)
        {
            var extraParameters = AuthUtilities.EncodeResumptionCookie(resumptionCookie);

            AuthenticationSettings authenticationSettings = AuthenticationSettings.GetFromAppSettings();

            Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext context = new Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext(authenticationSettings.EndpointUrl + "/" + authenticationSettings.Tenant);

            Uri redirectUri = new Uri(authenticationSettings.RedirectUrl);
            var uri         = await context.GetAuthorizationRequestUrlAsync(
                resourceId,
                authenticationSettings.ClientId,
                redirectUri,
                Microsoft.IdentityModel.Clients.ActiveDirectory.UserIdentifier.AnyUser,
                $"state={extraParameters}&response_mode=form_post");

            return(uri.ToString());
        }