/// <summary> /// Creates an authorization url for oauth requests /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns></returns> public override Task <BeginOAuthFlowResponse> BeginOAuthFlow(BeginOAuthFlowRequest request, ServerCallContext context) { Logger.Info("Getting Auth URL..."); // params for auth url var clientId = request.Configuration.ClientId; var redirectUrl = request.RedirectUrl; var scope = "contacts%20oauth%20tickets%20e-commerce"; var optionalScope = ""; // var scope = "oauth"; // var optionalScope = "contacts%20content%20reports%20social%20automation%20timeline%20business-intelligence%20forms%20files%20hubdb%20transactional-email%20integration-sync%20tickets%20e-commerce%20accounting%20sales-email-read%20forms-uploaded-files%20crm.import%20files.ui_hidden.read%20crm.objects.marketing_events.read%20crm.objects.marketing_events.write%20crm.schemas.custom.read%20crm.objects.custom.read%20crm.objects.custom.write"; // build auth url var authUrl = String.Format( "https://app.hubspot.com/oauth/authorize?client_id={0}&redirect_uri={1}&scope={2}&optional_scope={3}", clientId, redirectUrl, scope, optionalScope); // return auth url var oAuthResponse = new BeginOAuthFlowResponse { AuthorizationUrl = authUrl }; Logger.Info($"Created Auth URL: {authUrl}"); return(Task.FromResult(oAuthResponse)); }
/// <summary> /// Creates an authorization url for oauth requests /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns></returns> public override Task <BeginOAuthFlowResponse> BeginOAuthFlow(BeginOAuthFlowRequest request, ServerCallContext context) { Logger.Info("Getting Auth URL..."); // params for auth url var clientId = request.Configuration.ClientId; var responseType = "code"; var redirectUrl = request.RedirectUrl; var prompt = "consent"; var display = "popup"; // build auth url var authUrl = string.Format( "https://login.salesforce.com/services/oauth2/authorize?client_id={0}&response_type={1}&redirect_uri={2}&prompt={3}&display={4}", clientId, responseType, redirectUrl, prompt, display); // return auth url var oAuthResponse = new BeginOAuthFlowResponse { AuthorizationUrl = authUrl }; Logger.Info($"Created Auth URL: {authUrl}"); return(Task.FromResult(oAuthResponse)); }
/// <summary> /// Creates an authorization url for oauth requests /// </summary> /// <param name="request"></param> /// <param name="context"></param> /// <returns></returns> public override Task <BeginOAuthFlowResponse> BeginOAuthFlow(BeginOAuthFlowRequest request, ServerCallContext context) { Logger.SetLogPrefix("begin_oauth"); Logger.Info("Getting Auth URL..."); // params for auth url var scope = "ZohoCRM.users.all,ZohoCRM.org.all,ZohoCRM.settings.all,ZohoCRM.modules.all"; var clientId = request.Configuration.ClientId; var responseType = "code"; var accessType = "offline"; var redirectUrl = request.RedirectUrl; var prompt = "consent"; // build auth url var authUrl = String.Format( "https://accounts.zoho.com/oauth/v2/auth?scope={0}&client_id={1}&response_type={2}&access_type={3}&redirect_uri={4}&prompt={5}", scope, clientId, responseType, accessType, redirectUrl, prompt); // return auth url var oAuthResponse = new BeginOAuthFlowResponse { AuthorizationUrl = authUrl }; Logger.Info($"Created Auth URL: {authUrl}"); return(Task.FromResult(oAuthResponse)); }
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(); }