Ejemplo n.º 1
0
        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}"
                }
            });
        }
Ejemplo n.º 2
0
        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
                }
            });
        }
    }
Ejemplo n.º 3
0
        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; ");
            }
        }
Ejemplo n.º 4
0
        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
            {
            }
        }