Exemple #1
0
        private async Task <HttpListenerContext> HandleAuthCallback(HttpListener listener)
        {
            string[] requestedScopes = AuthorizationScopes.ToArray();
            string   flattenedScopes = string.Join("+", requestedScopes);

            string url = $"{this.configuration.LoginUrl}?client_id={this.configuration.ClientId}&response_type={oauthFlow}&scope={flattenedScopes}&redirect_uri={configuration.CallbackUrl}";

            if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
            {
                url = url.Replace("&", "^&");
                Process.Start(new ProcessStartInfo("cmd", $"/c start {url}"));
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
            {
                Process.Start("open", url);
            }
            else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
            {
                Process.Start("xdg-open", url);
            }
            else
            {
                throw new PlatformNotSupportedException();
            }

            HttpListenerContext context = await listener.GetContextAsync();

            return(context);
        }
        public void ToArray_ReturnsAllScopesInArray()
        {
            // Arrange
            string[] scopes = Array.Empty <string>();

            // Act
            scopes = AuthorizationScopes.ToArray();

            // Assert
            Assert.IsTrue(scopes.Contains(AuthorizationScopes.ApiProjectDelete));
            Assert.IsTrue(scopes.Contains(AuthorizationScopes.ApiProjectRead));
            Assert.IsTrue(scopes.Contains(AuthorizationScopes.ApiProjectWrite));
            Assert.IsTrue(scopes.Contains(AuthorizationScopes.ApiTaskDelete));
            Assert.IsTrue(scopes.Contains(AuthorizationScopes.ApiTaskRead));
            Assert.IsTrue(scopes.Contains(AuthorizationScopes.ApiTaskWrite));
            Assert.IsTrue(scopes.Contains(AuthorizationScopes.OpenId));
        }