Exemple #1
0
        public async Task BeginOAuthFlowTest()
        {
            // setup
            var mockHttp = GetMockHttpMessageHandler();

            Server server = new Server
            {
                Services = { Publisher.BindService(new PluginSalesforce.Plugin.Plugin(mockHttp.ToHttpClient())) },
                Ports    = { new ServerPort("localhost", 0, ServerCredentials.Insecure) }
            };

            server.Start();

            var port = server.Ports.First().BoundPort;

            var channel = new Channel($"localhost:{port}", ChannelCredentials.Insecure);
            var client  = new Publisher.PublisherClient(channel);

            var request = new BeginOAuthFlowRequest()
            {
                Configuration = new OAuthConfiguration
                {
                    ClientId          = "client",
                    ClientSecret      = "secret",
                    ConfigurationJson = "{}"
                },
                RedirectUrl = "http://test.com"
            };

            var clientId     = request.Configuration.ClientId;
            var responseType = "code";
            var redirectUrl  = request.RedirectUrl;
            var prompt       = "consent";
            var display      = "popup";

            var authUrl = String.Format(
                "https://test.salesforce.com/services/oauth2/authorize?client_id={0}&response_type={1}&redirect_uri={2}&prompt={3}&display={4}",
                clientId,
                responseType,
                redirectUrl,
                prompt,
                display);

            // act
            var response = client.BeginOAuthFlow(request);

            // assert
            Assert.IsType <BeginOAuthFlowResponse>(response);
            Assert.Equal(authUrl, response.AuthorizationUrl);

            // cleanup
            await channel.ShutdownAsync();

            await server.ShutdownAsync();
        }