public async Task <APIGatewayProxyResponse> HandleAsync(APIGatewayProxyRequest input, ILambdaContext context) { var ssmClient = new Amazon.SimpleSystemsManagement.AmazonSimpleSystemsManagementClient(); var googleOauthClientId = await ssmClient.GetParameterAsync(new GetParameterRequest { Name = "/GoogleOauthProxy/GoogleClientId" }); var googleOauthClientSecret = await ssmClient.GetParameterAsync(new GetParameterRequest { Name = "/GoogleOauthProxy/GoogleSecretKey" }); var clientSecrets = new ClientSecrets { ClientId = googleOauthClientId.Parameter.Value, ClientSecret = googleOauthClientSecret.Parameter.Value }; var state = JsonConvert.DeserializeObject <State>(input.QueryStringParameters["state"]); var authorisationFlow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer { ClientSecrets = clientSecrets }); return(new APIGatewayProxyResponse { StatusCode = 303, Headers = new Dictionary <string, string> { ["Access-Control-Allow-Origin"] = "*", ["Location"] = $"{state.ReturnUrl}?code={input.QueryStringParameters["code"]}&state={state.OauthState}" } }); }
public async Task <APIGatewayProxyResponse> HandleAsync(APIGatewayProxyRequest input, ILambdaContext context) { var ssmClient = new Amazon.SimpleSystemsManagement.AmazonSimpleSystemsManagementClient(); var googleOauthClientId = await ssmClient.GetParameterAsync(new GetParameterRequest { Name = "/GoogleOauthProxy/GoogleClientId" }); var googleOauthClientSecret = await ssmClient.GetParameterAsync(new GetParameterRequest { Name = "/GoogleOauthProxy/GoogleSecretKey" }); var googleOauthUrlRegex = await ssmClient.GetParameterAsync(new GetParameterRequest { Name = "/GoogleOauthProxy/UrlRegex" }); var returnUrl = input.QueryStringParameters["redirectUri"]; var urlRegex = new Regex(googleOauthUrlRegex.Parameter.Value); if (!urlRegex.IsMatch(returnUrl)) { return new APIGatewayProxyResponse { StatusCode = 403 } } ; var clientSecrets = new ClientSecrets { ClientId = googleOauthClientId.Parameter.Value, ClientSecret = googleOauthClientSecret.Parameter.Value }; var authorisationFlow = new GoogleAuthorizationCodeFlow(new GoogleAuthorizationCodeFlow.Initializer { ClientSecrets = clientSecrets, Scopes = new[] { "email" }, UserDefinedQueryParams = new[] { new KeyValuePair <string, string>("hd", "myunidays.com") } }); var authorisationApp = new AuthorizationCodeWebApp(authorisationFlow, "https://" + input.Headers["Host"] + "/Prod/google-oauth/callback", JsonConvert.SerializeObject(new { returnUrl, state = input.QueryStringParameters["state"] })); var result = await authorisationApp.AuthorizeAsync(string.Empty, CancellationToken.None); var location = result.RedirectUri; return(new APIGatewayProxyResponse { StatusCode = 303, Headers = new Dictionary <string, string> { ["Access-Control-Allow-Origin"] = "*", ["Location"] = location } }); } }
public static string GetConnectionString() { Amazon.SimpleSystemsManagement.AmazonSimpleSystemsManagementClient client = new Amazon.SimpleSystemsManagement.AmazonSimpleSystemsManagementClient(); try { var result = client.GetParameterAsync(new Amazon.SimpleSystemsManagement.Model.GetParameterRequest { Name = SSMParameterName }).Result; return(result.Parameter.Value); }catch { return("Server=findmyhaus-db-instance-1.cs95hzohy0fj.ap-southeast-1.rds.amazonaws.com;Port=5432;Database=findhaus;User Id=postgres;Password = Password1; "); } }
public void Invoke(CancellationToken cancellationToken) { if (cancellationToken.IsCancellationRequested) { return; } ThreadHelper.JoinableTaskFactory.Run(() => { var ssmClient = new Amazon.SimpleSystemsManagement.AmazonSimpleSystemsManagementClient(Amazon.RegionEndpoint.GetBySystemName(Options.Instance.AWSKMSRegion)); string name, secret, keyalias = ""; var prompt = new Prompt(); prompt.promptMessage.Text = "Supply a name for the parameter!"; prompt.ShowDialog(); name = prompt.ResponseText; if (name is null || name == String.Empty) { return(System.Threading.Tasks.Task.CompletedTask); } var list = new Amazon.KeyManagementService.AmazonKeyManagementServiceClient().ListAliases(new ListAliasesRequest() { }).Aliases.Select(e => new { e.AliasName, e.AliasArn }); var listchooser = new ListChooser(list.Select(e => e.AliasName).ToList()); listchooser.ShowDialog(); keyalias = listchooser.ListElement.SelectedItem as string; if (keyalias is null || keyalias == String.Empty) { return(System.Threading.Tasks.Task.CompletedTask); } var promptv = new Prompt(); promptv.promptMessage.Text = "Validate the secret (remove '', etc.)!"; promptv.ResponseText = value; promptv.ShowDialog(); secret = promptv.ResponseText; if (secret is null || secret == String.Empty) { return(System.Threading.Tasks.Task.CompletedTask); } ssmClient.PutParameterAsync(new Amazon.SimpleSystemsManagement.Model.PutParameterRequest() { KeyId = keyalias, Value = secret, Type = "SecureString", Name = name }).Wait(); _span.TextBuffer.Replace(_span.GetSpan(_snapshot), String.Format(replacementTexts[language], name, Options.Instance.AWSSSMRegion)); return(System.Threading.Tasks.Task.CompletedTask); }); }
static Notifications() { string SSMParameterName = @"/FindHaus/HouseService/SnsTopic"; try { Amazon.SimpleSystemsManagement.AmazonSimpleSystemsManagementClient client = new Amazon.SimpleSystemsManagement.AmazonSimpleSystemsManagementClient(); var result = client.GetParameterAsync(new Amazon.SimpleSystemsManagement.Model.GetParameterRequest { Name = SSMParameterName }).Result; SnsTopicArn = result.Parameter.Value; } catch { } }
public static async Task <T> GetParameters <T>(string awsRegion, string prefix = "") where T : new() { var properties = typeof(T).GetProperties().ToDictionary(p => prefix + p.Name); using (var client = new SsmClient(RegionEndpoint.GetBySystemName(awsRegion))) { var request = new GetParametersRequest { Names = properties.Keys.ToList(), WithDecryption = true, }; var response = await client.GetParametersAsync(request).ConfigureAwait(false); var result = new T(); foreach (var responseParameter in response.Parameters) { properties[responseParameter.Name].SetValue(result, responseParameter.Value); } // TODO: Handle response.InvalidParameters return(result); } }