private static void LoadSettings(string settingsResourcePartialName = "settings.json") { SetDefaults(); var storedSettings = GetStoredSettings(settingsResourcePartialName); if (storedSettings == null) return; try { var ic = new ImmutableCredentials(storedSettings.AccessKeyId, storedSettings.SecretAccessKey, storedSettings.SessionToken); Credentials = new StoredCredentials(ic); } catch(Exception e) { Console.WriteError("Unable to parse get credentials from settings file, defaulting to anonymous credentials. Exception: {0}", e.ToString()); Credentials = new AnonymousAWSCredentials(); } try { RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(storedSettings.RegionEndpoint); } catch(Exception e) { Console.WriteError("Unable to parse RegionEndpoint from settings file, defaulting to {0}. Exception: {1}", DefaultRegion, e.ToString()); RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(DefaultRegion); } ResultsBucket = storedSettings.ResultsBucket; ResultsTopic = storedSettings.ResultsTopic; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// private async Task <bool> _Login() { try { // Already authenticated? if (m_idToken != null && m_accessToken != null && m_refreshToken != null) { return(true); } // Autheticate to Amazon to get access token AWSCredentials credentials = new Amazon.Runtime.AnonymousAWSCredentials(); string systemName = COGNITO_USER_POOL_ID.Split('_')[0]; RegionEndpoint region = RegionEndpoint.GetBySystemName(systemName); using (IAmazonCognitoIdentityProvider provider = new AmazonCognitoIdentityProviderClient(credentials, region)) { CognitoUserPool userPool = new CognitoUserPool(COGNITO_USER_POOL_ID, COGNITO_CLIENT_ID, provider); CognitoUser user = new CognitoUser(m_evnexUsername, COGNITO_CLIENT_ID, userPool, provider); InitiateSrpAuthRequest authRequest = new InitiateSrpAuthRequest() { Password = m_evnexPassword }; AuthFlowResponse response = await user.StartWithSrpAuthAsync(authRequest).ConfigureAwait(false); m_idToken = response.AuthenticationResult.IdToken; m_accessToken = response.AuthenticationResult.AccessToken; m_refreshToken = response.AuthenticationResult.RefreshToken; } logger.Info("EvnexV2 Login succeeded"); return(true); } catch (Exception ex) { logger.Error(ex, "EvnexV2 Login failed. " + ex.Message); } return(false); }
private static void SetDefaults() { Credentials = new AnonymousAWSCredentials(); RegionEndpoint = Amazon.RegionEndpoint.GetBySystemName(DefaultRegion); }