Example #1
0
        public async Task <PhoneNumberCredentialsDTO> SendAuthenticationCodeToMobilePhone(PhoneNumberCredentialsDTO credentialsDTO)
        {
            try
            {
                var statXAuthResponse = await _statXIntegration.Login(credentialsDTO.ClientName, credentialsDTO.PhoneNumber);

                if (!string.IsNullOrEmpty(statXAuthResponse.Error))
                {
                    credentialsDTO.Error = statXAuthResponse.Error;
                }

                credentialsDTO.ClientId = statXAuthResponse.ClientId;
                credentialsDTO.Title    = "Enter the verification code from your StatX App: ";
                credentialsDTO.Message  = "* To find your verification code, go to your StatX App (download if necessary from an App store), then tap \"Settings\", \"Additional Authorizations\", and finally \"Get Code\". Note: the code is NOT in your SMS messages.";

                return(credentialsDTO);
            }
            catch (Exception ex)
            {
                await _hubLoggerService.ReportTerminalError(ex, credentialsDTO.Fr8UserId);

                credentialsDTO.Error = "An error occurred while trying to send login code, please try again later.";

                return(credentialsDTO);
            }
        }
        public async Task <AuthorizationTokenDTO> GenerateOAuthToken(ExternalAuthenticationDTO externalAuthDTO)
        {
            try
            {
                var query         = HttpUtility.ParseQueryString(externalAuthDTO.RequestQueryString);
                var oAuthToken    = query["oauth_token"];
                var oAuthVerifier = query["oauth_verifier"];
                var realmId       = query["realmId"];
                var state         = query["state"];
                var dataSource    = query["dataSource"];

                if (string.IsNullOrEmpty(oAuthToken) ||
                    string.IsNullOrEmpty(oAuthVerifier) ||
                    string.IsNullOrEmpty(realmId) ||
                    string.IsNullOrEmpty(dataSource))
                {
                    throw new ApplicationException("OAuth Token or OAuth Verifier or Realm ID or Data Source is empty.");
                }

                var authToken = await _authenticator.GetAuthToken(oAuthToken, oAuthVerifier, realmId, state);

                return(authToken);
            }
            catch (Exception ex)
            {
                await _loggerService.ReportTerminalError(ex, externalAuthDTO.Fr8UserId);

                return(new AuthorizationTokenDTO()
                {
                    Error = "An error occurred while trying to authorize, please try again later."
                });
            }
        }
Example #3
0
        public async Task <AuthorizationTokenDTO> GenerateOAuthToken(ExternalAuthenticationDTO externalAuthDTO)
        {
            try
            {
                var    query = HttpUtility.ParseQueryString(externalAuthDTO.RequestQueryString);
                string code  = query["code"];
                string state = query["state"];

                if (string.IsNullOrEmpty(code) || string.IsNullOrEmpty(state))
                {
                    throw new ApplicationException("Code or State is empty.");
                }

                var oauthToken = _googleIntegration.GetToken(code);
                var email      = await _googleIntegration.GetExternalUserId(oauthToken);

                return(new AuthorizationTokenDTO()
                {
                    Token = JsonConvert.SerializeObject(oauthToken),
                    ExternalStateToken = state,
                    ExternalAccountId = email
                });
            }
            catch (Exception ex)
            {
                await _loggerService.ReportTerminalError(ex, externalAuthDTO.Fr8UserId);

                return(new AuthorizationTokenDTO()
                {
                    Error = "An error occurred while trying to authorize, please try again later."
                });
            }
        }
Example #4
0
        public async Task <Crate> ProcessEvent(string curExternalEventPayload)
        {
            try
            {
                var curEventEnvelope = SalesforceNotificationParser.GetEnvelopeInformation(curExternalEventPayload);

                string accountId = string.Empty;

                if (curEventEnvelope.Body.Notifications.NotificationList != null && curEventEnvelope.Body.Notifications.NotificationList.Length > 0)
                {
                    accountId = curEventEnvelope.Body.Notifications.NotificationList[0].SObject.OwnerId;
                }

                //prepare the content from the external event payload
                var eventReportContent = new EventReportCM
                {
                    EventNames        = GetEventNames(curEventEnvelope),
                    EventPayload      = ExtractEventPayload(curEventEnvelope),
                    ExternalAccountId = accountId,
                    Manufacturer      = "Salesforce",
                };

                return(Crate.FromContent("Standard Event Report", eventReportContent));
            }
            catch (Exception e)
            {
                await _loggerService.ReportTerminalError(e);

                throw new Exception($"Error while processing. \r\n{curExternalEventPayload}");
            }
        }
        public async Task <AuthorizationTokenDTO> GenerateInternalOAuthToken(CredentialsDTO curCredentials)
        {
            try
            {
                var authToken = await ObtainAuthToken(curCredentials);

                if (authToken == null)
                {
                    return(new AuthorizationTokenDTO()
                    {
                        Error = "Unable to authenticate in DocuSign service, invalid login name or password."
                    });
                }

                var authorizationTokenDTO = new AuthorizationTokenDTO()
                {
                    Token             = JsonConvert.SerializeObject(authToken),
                    ExternalAccountId = curCredentials.Username,
                    AuthCompletedNotificationRequired = true
                };

                string demoAccountStr = string.Empty;
                if (curCredentials.IsDemoAccount)
                {
                    demoAccountStr = CloudConfigurationManager.GetSetting("DemoAccountAttributeString");
                }

                if (authorizationTokenDTO.AdditionalAttributes == null)
                {
                    authorizationTokenDTO.AdditionalAttributes = demoAccountStr;
                }
                else if (!authorizationTokenDTO.AdditionalAttributes.Contains(demoAccountStr))
                {
                    authorizationTokenDTO.AdditionalAttributes += demoAccountStr;
                }
                return(authorizationTokenDTO);
            }
            catch (Exception ex)
            {
                await _loggerService.ReportTerminalError(ex, curCredentials.Fr8UserId);

                return(new AuthorizationTokenDTO()
                {
                    Error = "An error occurred while trying to authorize, please try again later."
                });
            }
        }
Example #6
0
        public async Task <AuthorizationTokenDTO> GenerateOAuthToken(ExternalAuthenticationDTO externalAuthDTO)
        {
            try
            {
                return(await _authentication.Authenticate(externalAuthDTO));
            }
            catch (Exception ex)
            {
                await _loggerService.ReportTerminalError(ex, externalAuthDTO.Fr8UserId);

                return(await Task.FromResult(
                           new AuthorizationTokenDTO()
                {
                    Error = "An error occurred while trying to authorize, please try again later."
                }
                           ));
            }
        }
Example #7
0
        public async Task <AuthorizationTokenDTO> GenerateOAuthToken(ExternalAuthenticationDTO externalAuthDTO)
        {
            try
            {
                var    query = HttpUtility.ParseQueryString(externalAuthDTO.RequestQueryString);
                string code  = query["code"];
                string state = query["state"];

                if (string.IsNullOrEmpty(code) || string.IsNullOrEmpty(state))
                {
                    throw new ApplicationException("Code or State is empty.");
                }

                var oauthTokenData = await _asanaOAuth.GetOAuthTokenDataAsync(code);

                var userInfo            = oauthTokenData.Value <JObject>("data");
                var secondsToExpiration = oauthTokenData.Value <int>("expires_in");
                var expirationDate      = _asanaOAuth.CalculateExpirationTime(secondsToExpiration);

                return(new AuthorizationTokenDTO
                {
                    Token = oauthTokenData.ToString(),
                    ExternalAccountId = userInfo.Value <string>("id"),
                    ExternalAccountName = userInfo.Value <string>("name"),
                    ExternalStateToken = state,
                    ExpiresAt = expirationDate,
                    AdditionalAttributes = expirationDate.ToString("O")
                });
            }
            catch (Exception ex)
            {
                await _loggerService.ReportTerminalError(ex, externalAuthDTO.Fr8UserId);

                return(new AuthorizationTokenDTO()
                {
                    Error = "An error occurred while trying to authorize, please try again later."
                });
            }
        }
Example #8
0
        public async Task <AuthorizationTokenDTO> GenerateOAuthToken(ExternalAuthenticationDTO externalAuthDTO)
        {
            try
            {
                string code;
                string state;

                ParseCodeAndState(externalAuthDTO.RequestQueryString, out code, out state);

                if (string.IsNullOrEmpty(code) || string.IsNullOrEmpty(state))
                {
                    throw new ApplicationException("Code or State is empty.");
                }

                var oauthToken = await _slackIntegration.GetOAuthToken(code);

                var userInfo = await _slackIntegration.GetUserInfo(oauthToken);

                return(new AuthorizationTokenDTO
                {
                    Token = oauthToken,
                    ExternalAccountId = userInfo.UserId,
                    ExternalAccountName = userInfo.UserName,
                    ExternalDomainId = userInfo.TeamId,
                    ExternalDomainName = userInfo.TeamName,
                    ExternalStateToken = state,
                });
            }
            catch (Exception ex)
            {
                await _loggerService.ReportTerminalError(ex, externalAuthDTO.Fr8UserId);

                return(new AuthorizationTokenDTO()
                {
                    Error = "An error occurred while trying to authorize, please try again later."
                });
            }
        }
        public async Task <AuthorizationTokenDTO> GenerateOAuthToken(
            ExternalAuthenticationDTO externalAuthDTO)
        {
            try
            {
                return(_authentication.Authenticate(externalAuthDTO));
            }
            catch (Exception ex)
            {
                //The event reporting mechanism does not give the actual error message and it has been commented out in the BaseTerminal#ReportTerminalError
                //Logging explicitly to log4net to see the logs in the App Insights.
                //Logger.GetLogger().Error("Terminal SalesForce Authentication error happened. The error message is " + ex.Message);
                Logger.GetLogger().Error($"Terminal SalesForce Authentication error happened. Fr8UserId = {externalAuthDTO.Fr8UserId} The error message is {ex.Message} ");

                //Report the terminal error in the standard Fr8 Event Reporting mechanism
                await _loggerService.ReportTerminalError(ex, externalAuthDTO.Fr8UserId);

                return(new AuthorizationTokenDTO
                {
                    Error = string.Format("An error occured ({0}) while trying to authenticate, please try again later.", ex.Message)
                });
            }
        }
Example #10
0
        public async Task <AuthorizationTokenDTO> GenerateOAuthToken(
            ExternalAuthenticationDTO externalAuthDTO)
        {
            try
            {
                var    query = HttpUtility.ParseQueryString(externalAuthDTO.RequestQueryString);
                string code  = query["code"];
                string state = query["state"];

                string accessUrl = "https://api.box.com/oauth2/token";

                string url = accessUrl;

                string payload = $"grant_type=authorization_code&code={HttpUtility.UrlEncode(code)}" +
                                 $"&client_id={HttpUtility.UrlEncode(BoxHelpers.ClientId)}&" +
                                 $"&client_secret={HttpUtility.UrlEncode(BoxHelpers.Secret)}" +
                                 $"&redirect_uri={HttpUtility.UrlEncode(BoxHelpers.RedirectUri)}";

                var httpClient = new HttpClient(new HttpClientHandler
                {
                    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
                })
                {
                    BaseAddress = new Uri(url)
                };
                httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
                httpClient.DefaultRequestHeaders.Add("User-Agent", "oauth2-draft-v10");
                HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, accessUrl);
                request.Content = new StringContent(payload, Encoding.UTF8,
                                                    "application/x-www-form-urlencoded");

                var result = await httpClient.SendAsync(request);

                var response = await result.Content.ReadAsStringAsync();

                var jsonObj = JsonConvert.DeserializeObject <JObject>(response);

                var token = new BoxAuthTokenDO(
                    jsonObj.Value <string>("access_token"),
                    jsonObj.Value <string>("refresh_token"),
                    DateTime.UtcNow.AddSeconds(jsonObj.Value <int>("expires_in"))
                    );

                var userId = await new BoxService(token).GetCurrentUserLogin();

                return(new AuthorizationTokenDTO()
                {
                    Token = JsonConvert.SerializeObject(token),
                    ExternalStateToken = state,
                    ExternalAccountId = userId
                });
            }
            catch (Exception ex)
            {
                await _loggerService.ReportTerminalError(ex);

                Logger.GetLogger().Error(ex.Message);
                return(await Task.FromResult(
                           new AuthorizationTokenDTO()
                {
                    Error = "An error occurred while trying to authorize, please try again later."
                }
                           ));
            }
        }