﻿
{"id":26157,"date":"2023-02-17T22:16:47","date_gmt":"2023-02-17T22:16:47","guid":{"rendered":"https:\/\/www.gencayyildiz.com\/blog\/?p=26157"},"modified":"2023-02-17T22:16:47","modified_gmt":"2023-02-17T22:16:47","slug":"net-lambda-authorizer-ile-amazon-api-gatewayin-guvenligini-saglama","status":"publish","type":"post","link":"https:\/\/www.gencayyildiz.com\/blog\/net-lambda-authorizer-ile-amazon-api-gatewayin-guvenligini-saglama\/","title":{"rendered":".NET &#8211; Lambda Authorizer \u0130le Amazon API Gateway&#8217;in G\u00fcvenli\u011fini Sa\u011flama"},"content":{"rendered":"<div id=\"fb-root\"><\/div>\n<p>Merhaba,<\/p>\n<p>Bu i\u00e7eri\u011fimizde, \u00f6nceden <a href=\"https:\/\/www.gencayyildiz.com\/blog\/net-7-aws-lambda-ile-serverless-computing\/\" rel=\"noopener\" target=\"_blank\">.NET 7 \u2013 AWS Lambda \u0130le Serverless Computing<\/a> ve <a href=\"https:\/\/www.gencayyildiz.com\/blog\/net-ile-amazon-api-gateway-aws-lambda-dynamodb-entegrasyonu\/\" rel=\"noopener\" target=\"_blank\">.NET \u0130le Amazon API Gateway \u2013 AWS Lambda &#038; DynamoDB Entegrasyonu<\/a> ba\u015fl\u0131klar\u0131 alt\u0131nda kaleme ald\u0131\u011f\u0131m\u0131z makalelerimizde inceledi\u011fimiz AWS Lambda ve Amazon API Gateway konular\u0131n\u0131n g\u00fcvenli\u011fini sa\u011flayabilmek i\u00e7in Amazon taraf\u0131ndan sunulan <em>Lambda Authorizer<\/em> \u00f6zelli\u011fini inceleyecek ve teknik olarak nas\u0131l yap\u0131land\u0131r\u0131ld\u0131\u011f\u0131n\u0131 tecr\u00fcbe ediyor olaca\u011f\u0131z.<\/p>\n<h5>Lambda Authorizer Nedir?<\/h5>\n<p>Olu\u015fturdu\u011fumuz AWS Lambda Function&#8217;lar\u0131n\u0131 kullanabilmek i\u00e7in Amazon API Gateway taraf\u0131ndan \u00fcretilmi\u015f olan endpoint&#8217;lere kar\u015f\u0131n eri\u015fim haklar\u0131n\u0131 y\u00f6netmek i\u00e7in kullan\u0131lan esnek, yap\u0131land\u0131r\u0131labilir bir yetkilendirme mekanizmas\u0131d\u0131r.<\/p>\n<p>Lambda Authorizer iki farkl\u0131 t\u00fcrde mevcuttur;<\/p>\n<ul>\n<li><strong><em>Token-Based Lambda Authorizer<\/em><\/strong><br \/>\n\u0130lgili endpoint&#8217;e istek g\u00f6nderen ki\u015finin bilgilerini <em>Bearer Token<\/em> olarak <em>JSON Web Token(JWT)<\/em> format\u0131nda almaktad\u0131r. Ayr\u0131ca <em>TOKEN Authorizer<\/em> olarakta nitelendirilmektedir.\n<\/li>\n<li><strong><em>A Request Parameter-Based Lambda Authorizer<\/em><\/strong><br \/>\n\u0130lgili endpoint&#8217;e istek g\u00f6nderen ki\u015finin bilgilerini request&#8217;in header b\u00f6l\u00fcm\u00fcnden veya query string de\u011ferlerinden almaktad\u0131r. Bu y\u00f6nteme de ayr\u0131ca <em>REQUEST Authorizer<\/em> dendi\u011fini g\u00f6rebilirsiniz. WebSocket API&#8217;leri i\u00e7in bu y\u00f6ntem kullan\u0131ma daha yatk\u0131nd\u0131r.\n<\/li>\n<\/ul>\n<h5>Lambda Authorizer Workflow&#8217;u Nas\u0131ld\u0131r?<\/h5>\n<p>Amazon API Gateway \u00fczerinden AWS Lambda Function&#8217;lar\u0131na yap\u0131lan istek s\u00fcre\u00e7lerinde Lambda Authorizer&#8217;\u0131n sergiledi\u011fi davran\u0131\u015f\u0131 anlayabilmek i\u00e7in a\u015fa\u011f\u0131daki i\u015f ak\u0131\u015f\u0131 diyagram\u0131na g\u00f6z atabilirsiniz.<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama.png\" alt=\".NET - Lambda Authorizer \u0130le Amazon API Gateway&#039;in G\u00fcvenli\u011fini Sa\u011flama\" width=\"800\" height=\"450\" class=\"aligncenter size-full wp-image-26163\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama.png 800w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-300x169.png 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-768x432.png 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n<ul>\n<li><em style=\"color:gray;\">1. Ad\u0131m<\/em><br \/>\nClient, bir bearer token yahut request parameter e\u015fli\u011finde API Gateway \u00fczerinden bir endpoint&#8217;e istek g\u00f6nderir.\n<\/li>\n<li><em style=\"color:gray;\">2. Ad\u0131m<\/em><br \/>\nAPI Gateway ise endpoint&#8217;e kar\u015f\u0131l\u0131k bir Lambda Authorizer&#8217;\u0131n yap\u0131land\u0131r\u0131l\u0131p yap\u0131land\u0131r\u0131lmad\u0131\u011f\u0131n\u0131 kontrol eder. E\u011fer herhangi bir Lambda Authorizer yap\u0131land\u0131rmas\u0131 s\u00f6z konusu de\u011filse endpoint&#8217;e kar\u015f\u0131l\u0131k lambda function tetiklenecektir. Yok e\u011fer Lambda Authorizer yap\u0131land\u0131r\u0131lm\u0131\u015fsa s\u00fcrecin devam\u0131 ger\u00e7ekle\u015fecektir.\n<\/li>\n<li><em style=\"color:gray;\">3. Ad\u0131m<\/em><br \/>\nHedef lambda function tetiklenmeden \u00f6nce istek yapan ki\u015finin kimli\u011fi a\u015fa\u011f\u0131daki yollarla do\u011frulanmaya \u00e7al\u0131\u015f\u0131l\u0131r.<\/p>\n<ul>\n<li>Bir OAuth access token&#8217;\u0131 alabilmek i\u00e7in bir OAuth provider&#8217;\u0131n\u0131 \u00e7a\u011f\u0131rmak<\/li>\n<li>SAML onay\u0131 almak i\u00e7in bir SAML provider&#8217;\u0131n\u0131 \u00e7a\u011f\u0131rmak<\/li>\n<li>Request parameter de\u011ferine g\u00f6re bir IAM politikas\u0131 olu\u015fturmak<\/li>\n<li>Credentials bilgilerini bir database&#8217;den almak<\/li>\n<\/ul>\n<\/li>\n<li><em style=\"color:gray;\">4. Ad\u0131m<\/em><br \/>\nBu yollardan hangisi olursa olsun ba\u015far\u0131l\u0131 bir netice s\u00f6z konusuysa lambda authorizer, en az bir IAM politikas\u0131(IAM policy) ve ana tan\u0131mlay\u0131c\u0131(principal identifier) i\u00e7eren bir output object return ederek eri\u015fim izni verir.\n<\/li>\n<li><em style=\"color:gray;\">5. Ad\u0131m<\/em><br \/>\nVe son olarak API Gateway gelen IAM policy&#8217;i de\u011ferlendirir ve bu de\u011ferlendirme neticesinde eri\u015fim reddedilmi\u015fse 403 ACCESS_DENIED gibi uygun bir HTTP durum kodu d\u00f6nd\u00fcr\u00fcr. Yok e\u011fer eri\u015fime izin verilmi\u015fse API Gateway ilgili lambda function&#8217;\u0131 tetikler.\n<\/li>\n<\/ul>\n<p>T\u00fcm bu s\u00fcre\u00e7te lambda authorizer ayarlar\u0131nda \u00f6nbelle\u011fe alma(caching) etkinle\u015ftirildiyse e\u011fer API Gateway bu policy&#8217;i \u00f6nbelle\u011fe alacakt\u0131r ve b\u00f6ylece bir sonraki request&#8217;te lambda authorizer s\u00fcrecinin yeniden \u00e7al\u0131\u015ft\u0131r\u0131lmas\u0131na gerek kal\u0131nmayacakt\u0131r.<\/p>\n<h5>.NET \u0130le Lambda Authorizer Kullan\u0131m\u0131<\/h5>\n<p>\u015eimdi .NET ile lambda authorizer kullan\u0131m\u0131n\u0131 pratiksel olarak inceliyor olaca\u011f\u0131z. Bunun i\u00e7in \u00f6rnek olarak bir \u00f6nceki <a href=\"https:\/\/www.gencayyildiz.com\/blog\/net-ile-amazon-api-gateway-aws-lambda-dynamodb-entegrasyonu\/\" rel=\"noopener\" target=\"_blank\">.NET \u0130le Amazon API Gateway \u2013 AWS Lambda &#038; DynamoDB Entegrasyonu<\/a> ba\u015fl\u0131kl\u0131 makalede olu\u015fturdu\u011fumuz <a href=\"https:\/\/github.com\/gncyyldz\/AWS.API.Gateway.Example\" rel=\"noopener\" target=\"_blank\">\u015fu<\/a> projeyi temel olarak baz al\u0131yor olaca\u011f\u0131z.<span style=\"font-size:12px;\">(\u0130lgili makaledeki \u00e7al\u0131\u015fmay\u0131 bu i\u00e7eri\u011fimiz i\u00e7in ben deniz ba\u015ftan sona farkl\u0131 bir projede tekrar geli\u015ftirmi\u015f bulunuyorum. Bu i\u00e7erikle birlikte geli\u015ftirilmi\u015f nihai projeyi makalemizin sonundaki github adresinden edinebilirsiniz.)<\/span><\/p>\n<blockquote><p><em style=\"color:purple;\">Bir API Gateway&#8217;in t\u00fcm endpoint&#8217;lerine tek bir Lambda Authorizer eklenebilece\u011fi gibi her bir endpoint i\u00e7in ayr\u0131 Lambda Authorizer&#8217;da olu\u015fturulabilir. Bu tamamen sizlerin tercihine, kullan\u0131m durumuna ve i\u015fin gere\u011fine ba\u011fl\u0131d\u0131r.<\/em><\/p><\/blockquote>\n<p>Altyap\u0131 projemizdeki genel davran\u0131\u015f\u0131 h\u0131zl\u0131ca an\u0131msarsak e\u011fer; &#8216;persons&#8217; ad\u0131nda bir DynamoDB tablosuna veri ekleyen, eklenmi\u015f olan t\u00fcm person&#8217;lar\u0131 elde eden ve id bazl\u0131 sorgulama ger\u00e7ekle\u015ftiren \u00fc\u00e7 adet lambda function&#8217;\u0131m\u0131z mevcuttur. Ayr\u0131ca bu function&#8217;lara d\u0131\u015far\u0131dan eri\u015fim g\u00f6stermemizi sa\u011flayan ve \u00fc\u00e7 adet endpoint&#8217;e sahip olan API Gateway tasarlanm\u0131\u015ft\u0131r. \u015eimdi bizler Lambda Authorizer ile bu endpoint&#8217;lerin g\u00fcvenli\u011fini sa\u011flamaya \u00e7al\u0131\u015f\u0131yor olaca\u011f\u0131z. Bunun i\u00e7in iki yol benimseyece\u011fiz;<\/p>\n<table>\n<thead>\n<tr>\n<th width=\"50%\">1. Yol<\/th>\n<th>2. Yol<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td style=\"vertical-align: text-top;\">Username, password vs. gibi g\u00f6nderilen kimlik bilgilerini(credentials) okuyacak ve bunlar\u0131 do\u011frulayacak bir lambda function geli\u015ftirece\u011fiz. Bu do\u011frulama neticesinde bir JWT d\u00f6nd\u00fcrecek ve client&#8217;\u0131 b\u00f6ylece yetkilendirece\u011fiz. Client elde edece\u011fi bu JWT de\u011feri ile request&#8217;lerini ger\u00e7ekle\u015ftirecektir.<\/p>\n<p>Yani anlayaca\u011f\u0131n\u0131z authentication sorumlulu\u011funu \u00fcstlenecek bir uygulama olu\u015fturaca\u011f\u0131z.<\/td>\n<td style=\"vertical-align: text-top;\">Lambda Authorizer, \u00f6z\u00fcnde authorizer olarak davran\u0131\u015f sergileyen ap ayr\u0131 bir AWS Lambda projesidir. Yani function&#8217;d\u0131r. Bu function&#8217;\u0131n sorumlulu\u011fu, client&#8217;lar taraf\u0131ndan yap\u0131lan istek s\u00fcre\u00e7lerinde taraf\u0131m\u0131za iletilen JWT de\u011ferlerini do\u011frulamakt\u0131r. Bu do\u011frulama neticesinde hedef lambda function tetiklenecek yok e\u011fer do\u011frulama ger\u00e7ekle\u015fmezse Amazon API Gateway taraf\u0131ndan yorumlanabilecek\/anla\u015f\u0131labilecek bir IAM politikas\u0131 d\u00f6nd\u00fcr\u00fclecektir.<\/p>\n<p>Bu da bir authorization sorumlulu\u011fu \u00fcstlenecek uygulama olacakt\u0131r.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>O halde hadi ba\u015flayal\u0131m&#8230;<\/p>\n<p><strong>Authentication uygulamas\u0131n\u0131 geli\u015ftirme;<\/strong><\/p>\n<ul>\n<li><em style=\"color:green;\">Ad\u0131m 1 &#8211; <span style=\"font-size:12px;\">(Uygulama Olu\u015fturma)<\/span><\/em><br \/>\nSolution i\u00e7erisinde authentication i\u015flemlerini \u00fcstlenmesi i\u00e7in <em>AWS.Lambda.Authorizer.Example.Authentication<\/em> ad\u0131nda bir &#8216;Empty Function&#8217; olu\u015ftural\u0131m.\n<\/li>\n<li><em style=\"color:green;\">Ad\u0131m 2 &#8211; <span style=\"font-size:12px;\">(User Modelini Olu\u015fturma)<\/span><\/em><br \/>\nDo\u011frulama s\u00fcrecinde kullan\u0131c\u0131 bilgilerini tutmak i\u00e7in bir model tasarlayal\u0131m.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    &#x5B;DynamoDBTable(&quot;users&quot;)]\r\n    public class User\r\n    {\r\n        &#x5B;DynamoDBHashKey(&quot;email&quot;), DynamoDBProperty(&quot;email&quot;)]\r\n        &#x5B;JsonPropertyName(&quot;email&quot;)]\r\n        public string? Email { get; set; }\r\n        &#x5B;DynamoDBProperty(&quot;username&quot;)]\r\n        &#x5B;JsonPropertyName(&quot;username&quot;)]\r\n        public string? Username { get; set; }\r\n        &#x5B;DynamoDBProperty(&quot;password&quot;)]\r\n        &#x5B;JsonPropertyName(&quot;password&quot;)]\r\n        public string? Password { get; set; }\r\n    }\r\n<\/pre>\n<\/div>\n<\/li>\n<li><em style=\"color:green;\">Ad\u0131m 3 &#8211; <span style=\"font-size:12px;\">DynamoDB&#8217;de Tablo Olu\u015fturma<\/span><\/em><br \/>\nTasarlanan modele uygun DynamoDB&#8217;de tablo olu\u015ftural\u0131m.<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-1.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-1.png\" alt=\".NET - Lambda Authorizer \u0130le Amazon API Gateway&#039;in G\u00fcvenli\u011fini Sa\u011flama\" width=\"543\" height=\"407\" class=\"aligncenter size-full wp-image-26170\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-1.png 543w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-1-300x225.png 300w\" sizes=\"auto, (max-width: 543px) 100vw, 543px\" \/><\/a>\n<\/li>\n<li><em style=\"color:green;\">Ad\u0131m 4 &#8211; <span style=\"font-size:12px;\">Token Generate Etme<\/span><\/em><br \/>\nKullan\u0131c\u0131 bilgilerini do\u011frulad\u0131ktan sonra token \u00fcretimini ger\u00e7ekle\u015ftirecek servisi tasarlayal\u0131m.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    public interface ITokenGenerator\r\n    {\r\n        string GenerateJWT(User user, int minute);\r\n    }\r\n<\/pre>\n<\/div>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    public class TokenGenerator : ITokenGenerator\r\n    {\r\n        public string GenerateJWT(User user, int minute)\r\n        {\r\n            List&lt;Claim&gt; claims = new() {\r\n                new(ClaimTypes.Email, user.Email),\r\n                new(ClaimTypes.Name,user.Username)\r\n            };\r\n\r\n            byte&#x5B;] secretKey = Encoding.UTF8.GetBytes(&quot;doldur be meyhaneci, bo\u015f kalmas\u0131n kadehim...&quot;);\r\n\r\n            SigningCredentials credentials = new(\r\n                key: new SymmetricSecurityKey(secretKey),\r\n                algorithm: SecurityAlgorithms.HmacSha256);\r\n\r\n            JwtSecurityToken token = new(\r\n                claims: claims,\r\n                expires: DateTime.UtcNow.AddMinutes(minute),\r\n                signingCredentials: credentials);\r\n\r\n            JwtSecurityTokenHandler tokenHandler = new();\r\n            return tokenHandler.WriteToken(token);\r\n        }\r\n    }\r\n<\/pre>\n<\/div>\n<\/li>\n<li><em style=\"color:green;\">Ad\u0131m 5 &#8211; <span style=\"font-size:12px;\">GenerateTokenAsync Function&#8217;\u0131n\u0131 Tasarlama<\/span><\/em><br \/>\nBu ad\u0131mda da olu\u015fturdu\u011fumuz &#8216;TokenGenerator&#8217; s\u0131n\u0131f\u0131n\u0131 kullanarak gerekli JWT \u00fcretimini ger\u00e7ekle\u015ftirecek function&#8217;\u0131 tasarlayal\u0131m.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nusing Amazon.DynamoDBv2;\r\nusing Amazon.DynamoDBv2.DataModel;\r\nusing Amazon.Lambda.APIGatewayEvents;\r\nusing Amazon.Lambda.Core;\r\nusing AWS.Lambda.Authorizer.Example.Authentication.Models;\r\nusing AWS.Lambda.Authorizer.Example.Authentication.Services;\r\nusing AWS.Lambda.Authorizer.Example.Authentication.Services.Abstractions;\r\nusing Microsoft.Extensions.DependencyInjection;\r\nusing System.Text.Json;\r\n\r\n\/\/ Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.\r\n&#x5B;assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]\r\n\r\nnamespace AWS.Lambda.Authorizer.Example.Authentication;\r\n\r\npublic class Function\r\n{\r\n    readonly IServiceProvider _serviceProvider;\r\n    public Function()\r\n    {\r\n        ServiceCollection serviceCollection = new();\r\n        serviceCollection.AddScoped&lt;ITokenGenerator, TokenGenerator&gt;();\r\n        _serviceProvider = serviceCollection.BuildServiceProvider();\r\n    }\r\n    public async Task&lt;string&gt; GenerateTokenAsync(APIGatewayHttpApiV2ProxyRequest request, ILambdaContext context)\r\n    {\r\n        User? user = JsonSerializer.Deserialize&lt;User&gt;(request.Body);\r\n        AmazonDynamoDBClient dynamoDBClient = new();\r\n        DynamoDBContext dynamoDBContext = new(dynamoDBClient);\r\n\r\n        User hasUser = await dynamoDBContext.LoadAsync&lt;User&gt;(user.Email);\r\n        if (hasUser != null)\r\n        {\r\n            if (hasUser.Password != user.Password)\r\n                throw new Exception(&quot;Invalid credentials!&quot;);\r\n\r\n            using (IServiceScope scope = _serviceProvider.CreateScope())\r\n            {\r\n                ITokenGenerator tokenGenerator = scope.ServiceProvider.GetService&lt;ITokenGenerator&gt;();\r\n                return tokenGenerator.GenerateJWT(user, 3);\r\n            }\r\n        }\r\n        throw new Exception(&quot;User not found!&quot;);\r\n    }\r\n}\r\n\r\n<\/pre>\n<\/div>\n<\/li>\n<li><em style=\"color:green;\">Ad\u0131m 5 &#8211; <span style=\"font-size:12px;\">Function&#8217;\u0131 Publish Etme ve DynamoDB Eri\u015fim Politikas\u0131yla E\u015fle\u015ftirme<\/span><\/em><br \/>\n\u015eimdide olu\u015fturdu\u011fumuz function&#8217;\u0131 publish edelim.<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-2.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-2.png\" alt=\".NET - Lambda Authorizer \u0130le Amazon API Gateway&#039;in G\u00fcvenli\u011fini Sa\u011flama\" width=\"829\" height=\"547\" class=\"aligncenter size-full wp-image-26171\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-2.png 829w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-2-300x198.png 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-2-768x507.png 768w\" sizes=\"auto, (max-width: 829px) 100vw, 829px\" \/><\/a><a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-3.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-3-150x150.png\" alt=\".NET - Lambda Authorizer \u0130le Amazon API Gateway&#039;in G\u00fcvenli\u011fini Sa\u011flama\" width=\"150\" height=\"150\" class=\"alignleft size-thumbnail wp-image-26172\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-3-150x150.png 150w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-3-80x80.png 80w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/a><br \/>\nFunction&#8217;\u0131 publish ettikten sonra AWS Lambda servisinden yandaki gibi kontrol etmenizde fayda vard\u0131r. \u015eimdi bu lambda function ile DynamoDB aras\u0131nda ili\u015fki kuraca\u011f\u0131z. Bunun i\u00e7in IAM Service \u00fczerinden politikalara geliniz ve t\u00fcm aksiyonlar e\u015fli\u011finde DynamoDB eri\u015fim iznine sahip olan politikay\u0131 ilgili lambda function&#8217;la ili\u015fkilendiriniz.<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-4.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-4.png\" alt=\".NET - Lambda Authorizer \u0130le Amazon API Gateway&#039;in G\u00fcvenli\u011fini Sa\u011flama\" width=\"1338\" height=\"198\" class=\"aligncenter size-full wp-image-26173\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-4.png 1338w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-4-300x44.png 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-4-1024x152.png 1024w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-4-768x114.png 768w\" sizes=\"auto, (max-width: 1338px) 100vw, 1338px\" \/><\/a><a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-5.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-5.png\" alt=\".NET - Lambda Authorizer \u0130le Amazon API Gateway&#039;in G\u00fcvenli\u011fini Sa\u011flama\" width=\"1729\" height=\"226\" class=\"aligncenter size-full wp-image-26174\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-5.png 1729w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-5-300x39.png 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-5-1024x134.png 1024w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-5-768x100.png 768w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-5-1536x201.png 1536w\" sizes=\"auto, (max-width: 1729px) 100vw, 1729px\" \/><\/a>\n<\/li>\n<li><em style=\"color:green;\">Ad\u0131m 6 &#8211; <span style=\"font-size:12px;\">API Gateway \u0130le Endpoint Alma<\/span><\/em><br \/>\nVe nihai olarak art\u0131k function&#8217;a eri\u015fip, authentication i\u015flemlerini ba\u015far\u0131yla ger\u00e7ekle\u015ftirebilmek i\u00e7in bir API Gateway \u00fczerinden endpoint ayarlayal\u0131m. Tabi burada isterseniz mevcut API Gateway&#8217;lerden birini kullanabilir yahut s\u0131rf bu i\u015flem i\u00e7in ba\u015fl\u0131 ba\u015f\u0131na bir API Gateway olu\u015fturabilirsiniz. Ben genel anlamda endpoint&#8217;in origin&#8217;i de\u011fi\u015fmemesi i\u00e7in var olan bir API Gateway \u00fczerinden bu function&#8217;a \u00f6zel bir entegrasyonda bulunaca\u011f\u0131m. Bunun i\u00e7in API Gateway servisinde a\u015fa\u011f\u0131daki g\u00f6rseldeki gibi davran\u0131\u015f sergilenmesi yeterli olacakt\u0131r.<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama.gif\" alt=\".NET - Lambda Authorizer \u0130le Amazon API Gateway&#039;in G\u00fcvenli\u011fini Sa\u011flama\" width=\"800\" height=\"362\" class=\"aligncenter size-full wp-image-26175\" \/><\/a>G\u00f6r\u00fcld\u00fc\u011f\u00fc \u00fczere yeni ekledi\u011fimiz function&#8217;\u0131 API Gateway ile ili\u015fkilendirdik. Bu i\u015flemin ard\u0131ndan a\u015fa\u011f\u0131daki gibi endpoint tan\u0131mlamas\u0131nda bulunabiliriz.<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-1.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-1.gif\" alt=\".NET - Lambda Authorizer \u0130le Amazon API Gateway&#039;in G\u00fcvenli\u011fini Sa\u011flama\" width=\"800\" height=\"362\" class=\"aligncenter size-full wp-image-26176\" \/><\/a>\n<\/li>\n<li><em style=\"color:green;\">Ad\u0131m 7 &#8211; <span style=\"font-size:12px;\">Test<\/span><\/em><br \/>\nVe son olarak olu\u015fturdu\u011fumuz endpoint \u00fczerinden token talebinde bulunabiliriz.<br \/>\n<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-2.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-2.gif\" alt=\".NET - Lambda Authorizer \u0130le Amazon API Gateway&#039;in G\u00fcvenli\u011fini Sa\u011flama\" width=\"800\" height=\"438\" class=\"aligncenter size-full wp-image-26179\" \/><\/a>\n<\/li>\n<\/ul>\n<p>Evet, g\u00f6r\u00fcld\u00fc\u011f\u00fc \u00fczere authentication uygulamas\u0131n\u0131 ba\u015far\u0131yla geli\u015ftirmi\u015f bulunuyoruz. \u015eimdi s\u0131ra authorization uygulamas\u0131nda&#8230;<\/p>\n<p><strong>Authorization(Lambda Authorizer) uygulamas\u0131n\u0131 geli\u015ftirme;<\/strong><\/p>\n<ul>\n<li><em style=\"color:green;\">Ad\u0131m 1 &#8211; <span style=\"font-size:12px;\">Uygulama Olu\u015fturma<\/span><\/em><br \/>\nYine ilk olarak ayn\u0131 solution i\u00e7erisinde bu sefer de authorization i\u015flemlerini \u00fcstlenmesi i\u00e7in <em>AWS.Lambda.Authorizer.Example.Authorization<\/em> ad\u0131nda bir proje olu\u015ftural\u0131m.\n<\/li>\n<li><em style=\"color:green;\">Ad\u0131m 2 &#8211; <span style=\"font-size:12px;\">Token&#8217;\u0131 Do\u011frulama<\/span><\/em><br \/>\nAuthentication uygulamas\u0131ndan al\u0131nm\u0131\u015f olan token&#8217;\u0131 do\u011frulamak i\u00e7in gerekli servisi olu\u015ftural\u0131m.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    public interface ITokenValidator\r\n    {\r\n        ClaimsPrincipal ValidateToken(string accessToken);\r\n    }\r\n<\/pre>\n<\/div>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\n    public class TokenValidator : ITokenValidator\r\n    {\r\n        public ClaimsPrincipal ValidateToken(string accessToken)\r\n        {\r\n            JwtSecurityTokenHandler tokenHandler = new();\r\n\r\n            byte&#x5B;] secretKey = Encoding.UTF8.GetBytes(&quot;doldur be meyhaneci, bo\u015f kalmas\u0131n kadehim...&quot;);\r\n\r\n            TokenValidationParameters validationParameters = new()\r\n            {\r\n                ValidateLifetime = true,\r\n                ValidateAudience = false,\r\n                ValidateIssuer = false,\r\n                IssuerSigningKey = new SymmetricSecurityKey(secretKey),\r\n            };\r\n\r\n\r\n            try\r\n            {\r\n                ClaimsPrincipal claimsPrincipal = tokenHandler.ValidateToken(\r\n                     token: accessToken,\r\n                     validationParameters: validationParameters,\r\n                     validatedToken: out SecurityToken _);\r\n                return claimsPrincipal;\r\n            }\r\n            catch (Exception ex)\r\n            {\r\n                return null;\r\n            }\r\n        }\r\n    }\r\n<\/pre>\n<\/div>\n<\/li>\n<li><em style=\"color:green;\">Ad\u0131m 3 &#8211; <span style=\"font-size:12px;\">ValidateToken Function&#8217;\u0131n\u0131 Tasarlama<\/span><\/em><br \/>\n\u015eimdi de olu\u015fturdu\u011fumuz &#8216;TokenValidator&#8217; s\u0131n\u0131f\u0131n\u0131 kullanarak token&#8217;\u0131 do\u011frulayacak olan function&#8217;\u0131 olu\u015ftural\u0131m.<\/p>\n<div style=\"font-size:12px;\">\n<pre class=\"brush: jscript; title: ; notranslate\" title=\"\">\r\nusing Amazon.Lambda.APIGatewayEvents;\r\nusing Amazon.Lambda.Core;\r\nusing AWS.Lambda.Authorizer.Example.Authorization.Services;\r\nusing AWS.Lambda.Authorizer.Example.Authorization.Services.Abstractions;\r\nusing Microsoft.Extensions.DependencyInjection;\r\nusing System.Security.Claims;\r\nusing System.Text.Json;\r\n\r\n\/\/ Assembly attribute to enable the Lambda function's JSON input to be converted into a .NET class.\r\n&#x5B;assembly: LambdaSerializer(typeof(Amazon.Lambda.Serialization.SystemTextJson.DefaultLambdaJsonSerializer))]\r\n\r\nnamespace AWS.Lambda.Authorizer.Example.Authorization;\r\n\r\npublic class Function\r\n{\r\n    readonly IServiceProvider _serviceProvider;\r\n    public Function()\r\n    {\r\n        ServiceCollection serviceCollection = new();\r\n        serviceCollection.AddScoped&lt;ITokenValidator, TokenValidator&gt;();\r\n        _serviceProvider = serviceCollection.BuildServiceProvider();\r\n    }\r\n    public APIGatewayCustomAuthorizerResponse TokenValidator(APIGatewayCustomAuthorizerRequest request, ILambdaContext context)\r\n    {\r\n        string accessToken = request.Headers&#x5B;&quot;authorization&quot;];\r\n        ITokenValidator tokenValidator = _serviceProvider.GetRequiredService&lt;ITokenValidator&gt;();\r\n        ClaimsPrincipal claimsPrincipal = tokenValidator.ValidateToken(accessToken);\r\n\r\n        string? principalId = &quot;401&quot;;\r\n        if (claimsPrincipal is { Identity.IsAuthenticated: true })\r\n            principalId = claimsPrincipal.FindFirst(ClaimTypes.Name)?.Value;\r\n\r\n        return new APIGatewayCustomAuthorizerResponse()\r\n        {\r\n            PrincipalID = principalId,\r\n            PolicyDocument = new APIGatewayCustomAuthorizerPolicy\r\n            {\r\n                Statement = new List&lt;APIGatewayCustomAuthorizerPolicy.IAMPolicyStatement&gt;\r\n                    {\r\n                         new APIGatewayCustomAuthorizerPolicy.IAMPolicyStatement()\r\n                         {\r\n                             Effect = claimsPrincipal != null ? &quot;Allow&quot; : &quot;Deny&quot;,\r\n                             Resource = new HashSet&lt;string&gt;{ &quot;arn:aws:execute-api:ap-south-1:567921601443:uyv8v6df12\/*\/*&quot; },\r\n                             Action = new HashSet&lt;string&gt;{ &quot;execute-api:Invoke&quot; }\r\n                         }\r\n                    }\r\n            }\r\n        };\r\n    }\r\n}\r\n<\/pre>\n<\/div>\n<p>Evet, olu\u015fturulan function&#8217;\u0131n detaylar\u0131ndan bahsetmemiz gerekti\u011fi a\u015fikar. O halde ilk olarak <code>APIGatewayCustomAuthorizerRequest<\/code> ve <code>APIGatewayCustomAuthorizerResponse<\/code> olmak \u00fczere parametre ve geri d\u00f6n\u00fc\u015f t\u00fcrlerini ele alarak ba\u015flayal\u0131m. Bu referanslar, Lambda Authorizer i\u00e7in kullan\u0131lan \u00f6zel s\u0131n\u0131flard\u0131r. <code>APIGatewayCustomAuthorizerRequest<\/code> s\u0131n\u0131f\u0131 JWT do\u011frulamak i\u00e7in gelen istekleri temsil ederken bizlere bu istekle ilgili headers, query string ve di\u011fer bilgileri getirmektedir. Ayn\u0131 \u015fekilde <code>APIGatewayCustomAuthorizerResponse<\/code> s\u0131n\u0131f\u0131 ise yetkilendirme neticesinde gerekli bilgileri i\u00e7erecek olan (ad\u0131 \u00fczerinde) response&#8217;u temsil etmektedir.<\/p>\n<p><code>APIGatewayCustomAuthorizerResponse<\/code> nesnesinin property&#8217;lerine gelirsek e\u011fer; <code>PrincipalID<\/code> property&#8217;si, JWT do\u011fruland\u0131\u011f\u0131 taktirde &#8216;name&#8217; claim&#8217;inin de\u011ferini, yok e\u011fer do\u011frulanmazsa &#8220;401&#8221; de\u011ferini almaktad\u0131r. <code>PolicyDocument<\/code> property&#8217;si, <code>APIGatewayCustomAuthorizerPolicy<\/code> t\u00fcr\u00fcnden nesne alan bu property lambda authorizer taraf\u0131ndan API Gateway&#8217;e g\u00f6nderilen ve yetkilendirmenin ba\u015far\u0131l\u0131 olup olmad\u0131\u011f\u0131n\u0131 ifade edecek olan yan\u0131t ama\u00e7l\u0131 kullan\u0131lmaktad\u0131r. Bu nesnenin de &#8216;Effect&#8217;, &#8216;Resource&#8217; ve &#8216;Action&#8217; property&#8217;leri mevcuttur. Bu property&#8217;lerden; &#8216;Effect&#8217;, yetkilendirmenin ba\u015far\u0131l\u0131 olup olmad\u0131\u011f\u0131n\u0131 ifade etmektedir. \u00d6rnekte de g\u00f6r\u00fcld\u00fc\u011f\u00fc \u00fczere ba\u015far\u0131l\u0131ysa &#8216;Allow&#8217; de\u011filse &#8216;Deny&#8217; de\u011ferlerini almaktad\u0131r. &#8216;Resource&#8217;, i\u015flem yap\u0131lacak kayna\u011f\u0131n ad\u0131n\u0131 temsil etmektedir. &#8216;Action&#8217; ise i\u015flem yap\u0131lacak kayna\u011f\u0131n \u00fczerinde yap\u0131lacak eylemi\/i\u015flemi temsil etmektedir.<\/p>\n<p>Tabi burada &#8216;Resource&#8217; property&#8217;sine biraz daha odaklanmam\u0131z gerekmektedir. &#8216;Resource&#8217;, yap\u0131sal olarak bir ARN(Amazon Resource Name) format\u0131nda de\u011fer beklemektedir. ARN&#8217;ler AWS&#8217;de ki kaynaklar\u0131n benzersiz tan\u0131mlay\u0131c\u0131s\u0131d\u0131rlar. Misal olarak bir lambda function&#8217;\u0131n ARN de\u011feri \u015f\u00f6yle olmal\u0131d\u0131r:<\/p>\n<div style=\"text-align:center;\">\n<strong><span style=\"font-size:12px;color:purple;\">arn:aws:execute-api:<span style=\"color:red;\">&lt;aws-region&gt;<\/span>:<span style=\"color:orange;\">&lt;aws-account-id&gt;<\/span>:<span style=\"color:pink;\">&lt;amazon-gateway-id&gt;<\/span>\/*\/*<\/span><\/strong>\n<\/div>\n<ul style=\"font-size:12px;\">\n<li><span style=\"color:red;\">&lt;aws-region&gt;<\/span> : AWS servislerinin bulundu\u011fu b\u00f6lgenin de\u011ferini ifade eder.<\/li>\n<li><span style=\"color:orange;\">&lt;aws-account-id&gt;<\/span> : AWS Account ID&#8217;yi ifade eder. Bu de\u011fer i\u00e7in AWS sayfas\u0131ndan sa\u011f \u00fcst k\u00f6\u015fedeki profilinize t\u0131klaman\u0131z yeterli olacakt\u0131r.<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-6.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-6-300x75.png\" alt=\".NET - Lambda Authorizer \u0130le Amazon API Gateway&#039;in G\u00fcvenli\u011fini Sa\u011flama\" width=\"300\" height=\"75\" class=\"aligncenter size-medium wp-image-26184\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-6-300x75.png 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-6.png 330w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/li>\n<li><span style=\"color:pink;\">&lt;amazon-gateway-id&gt;<\/span> : API Gateway&#8217;in ID de\u011ferini ifade eder. Bu de\u011fer i\u00e7in ise ilgili API Gateway&#8217;in detaylar\u0131na bakman\u0131z yeterli olacakt\u0131r.<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-7.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-7-300x234.png\" alt=\".NET - Lambda Authorizer \u0130le Amazon API Gateway&#039;in G\u00fcvenli\u011fini Sa\u011flama\" width=\"300\" height=\"234\" class=\"aligncenter size-medium wp-image-26186\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-7-300x234.png 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-7.png 405w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><\/li>\n<\/ul>\n<\/li>\n<li><em style=\"color:green;\">Ad\u0131m 4 &#8211; <span style=\"font-size:12px;\">Function&#8217;\u0131 Publish Etme<\/span><\/em><br \/>\nOlu\u015fturulan function&#8217;\u0131 publish edelim.<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-8.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-8.png\" alt=\".NET - Lambda Authorizer \u0130le Amazon API Gateway&#039;in G\u00fcvenli\u011fini Sa\u011flama\" width=\"823\" height=\"550\" class=\"aligncenter size-full wp-image-26188\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-8.png 823w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-8-300x200.png 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-8-768x513.png 768w\" sizes=\"auto, (max-width: 823px) 100vw, 823px\" \/><\/a>\n<\/li>\n<li><em style=\"color:green;\">Ad\u0131m 5 &#8211; <span style=\"font-size:12px;\">Endpoint&#8217;e Lambda Authorizer Olarak Tan\u0131mlama<\/span><\/em><br \/>\nVe son olarak istenilen herhangi bir endpoint&#8217;in g\u00fcvenli\u011fini sa\u011flayabilmek i\u00e7in ilgili function&#8217;\u0131 o endpoint&#8217;e lambda authorizer olarak ekleyelim. Bunun i\u00e7in API Gateway sayfas\u0131nda istedi\u011finiz endpoint&#8217;i se\u00e7ebilirsiniz.<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-9.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-9.png\" alt=\".NET - Lambda Authorizer \u0130le Amazon API Gateway&#039;in G\u00fcvenli\u011fini Sa\u011flama\" width=\"1207\" height=\"403\" class=\"aligncenter size-full wp-image-26191\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-9.png 1207w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-9-300x100.png 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-9-1024x342.png 1024w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-9-768x256.png 768w\" sizes=\"auto, (max-width: 1207px) 100vw, 1207px\" \/><\/a>Misal olarak bizler yukar\u0131daki ekran g\u00f6r\u00fcnt\u00fcs\u00fcnde oldu\u011fu gibi GET t\u00fcr\u00fcnden olan &#8216;\/persons&#8217; endpoint&#8217;ine bu function&#8217;\u0131 authorizer olarak atamak istedi\u011fimiz taktirde ilgili endpoint&#8217;i se\u00e7ip devam\u0131nda sa\u011f taraftaki &#8216;Attach authorization&#8217; butonuna t\u0131klamal\u0131y\u0131z.<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-10.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-10.png\" alt=\".NET - Lambda Authorizer \u0130le Amazon API Gateway&#039;in G\u00fcvenli\u011fini Sa\u011flama\" width=\"751\" height=\"167\" class=\"aligncenter size-full wp-image-26192\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-10.png 751w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-10-300x67.png 300w\" sizes=\"auto, (max-width: 751px) 100vw, 751px\" \/><\/a>Ard\u0131ndan &#8216;Create and attach an authorizer&#8217; butonuna t\u0131klayarak devam edelim.<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-11.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-11.png\" alt=\".NET - Lambda Authorizer \u0130le Amazon API Gateway&#039;in G\u00fcvenli\u011fini Sa\u011flama\" width=\"1559\" height=\"630\" class=\"aligncenter size-full wp-image-26193\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-11.png 1559w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-11-300x121.png 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-11-1024x414.png 1024w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-11-768x310.png 768w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-11-1536x621.png 1536w\" sizes=\"auto, (max-width: 1559px) 100vw, 1559px\" \/><\/a>Devam\u0131nda ise authorizer type olarak &#8216;Lambda&#8217; sekmesini se\u00e7elim ve gerekli alanlar\u0131 yukar\u0131daki gibi doldural\u0131m.<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-12.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-12.png\" alt=\".NET - Lambda Authorizer \u0130le Amazon API Gateway&#039;in G\u00fcvenli\u011fini Sa\u011flama\" width=\"1545\" height=\"701\" class=\"aligncenter size-full wp-image-26194\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-12.png 1545w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-12-300x136.png 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-12-1024x465.png 1024w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-12-768x348.png 768w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-12-1536x697.png 1536w\" sizes=\"auto, (max-width: 1545px) 100vw, 1545px\" \/><\/a>Tasarlad\u0131\u011f\u0131m\u0131z lambda authorizer gelen istekleri do\u011frulamak i\u00e7in IAM politikas\u0131 d\u00f6nd\u00fcrd\u00fc\u011f\u00fcnden dolay\u0131 &#8216;IAM Policy&#8217; sekmesini se\u00e7elim.<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-13.png\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-13.png\" alt=\".NET - Lambda Authorizer \u0130le Amazon API Gateway&#039;in G\u00fcvenli\u011fini Sa\u011flama\" width=\"1320\" height=\"727\" class=\"aligncenter size-full wp-image-26195\" srcset=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-13.png 1320w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-13-300x165.png 300w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-13-1024x564.png 1024w, https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-13-768x423.png 768w\" sizes=\"auto, (max-width: 1320px) 100vw, 1320px\" \/><\/a>T\u00fcm bu i\u015flemler neticesinde API Gateway ekran\u0131nda &#8216;Authorization&#8217; sayfas\u0131na bakt\u0131\u011f\u0131m\u0131zda ilgili endpoint&#8217;in &#8216;Lambda Auth&#8217; ile i\u015faretlendi\u011fini g\u00f6rerek, yetkilendirilmeye tabii tutuldu\u011funu anlayabilmekteyiz.<\/p>\n<\/li>\n<li><em style=\"color:green;\">Ad\u0131m 6 &#8211; <span style=\"font-size:12px;\">Test<\/span><\/em><br \/>\nArt\u0131k yapt\u0131\u011f\u0131m\u0131z t\u00fcm bu \u00e7al\u0131\u015fmalar\u0131n nihai testini ger\u00e7ekle\u015ftirebiliriz.<a href=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-3.gif\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.gencayyildiz.com\/blog\/wp-content\/uploads\/2023\/02\/NET-Lambda-Authorizer-Ile-Amazon-API-Gatewayin-Guvenligini-Saglama-3.gif\" alt=\".NET - Lambda Authorizer \u0130le Amazon API Gateway&#039;in G\u00fcvenli\u011fini Sa\u011flama\" width=\"800\" height=\"438\" class=\"aligncenter size-full wp-image-26199\" \/><\/a>\n<\/li>\n<\/ul>\n<p>Evet&#8230; G\u00f6r\u00fcld\u00fc\u011f\u00fc \u00fczere Lambda Authorizer yap\u0131land\u0131rmas\u0131 i\u015fte bu kadar \ud83d\ude42 K\u0131ssadan hisse yaparsak, bir authentication bir de authorization i\u015flemlerinin sorumlulu\u011funu \u00fcstlenen ayr\u0131 function&#8217;lar taraf\u0131ndan rahatl\u0131kla ger\u00e7ekle\u015ftirilebilmekte ve hangi endpoint&#8217;i koruyacaksak ilgili authorization uygulamas\u0131 onunla e\u015fle\u015ftirilmektedir.<\/p>\n<p>\u0130lgilenenlerin faydalanmas\u0131 dile\u011fiyle&#8230;<br \/>\nSonraki yaz\u0131lar\u0131mda g\u00f6r\u00fc\u015fmek \u00fczere&#8230;<br \/>\n\u0130yi \u00e7al\u0131\u015fmalar&#8230;<\/p>\n<p>Not : \u00d6rnek projeyi a\u015fa\u011f\u0131daki github adresinden edinebilirsiniz.<br \/>\n<a href=\"https:\/\/github.com\/gncyyldz\/AWS.Lambda.Authorizer.Example\" rel=\"noopener\" target=\"_blank\">https:\/\/github.com\/gncyyldz\/AWS.Lambda.Authorizer.Example<\/a><\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Merhaba, Bu i\u00e7eri\u011fimizde, \u00f6nceden .NET 7 \u2013 AWS Lambda \u0130le Serverless Computing ve .NET \u0130le Amazon API Gateway \u2013 AWS Lambda &#038; DynamoDB Entegrasyonu ba\u015fl\u0131klar\u0131 alt\u0131nda kaleme ald\u0131\u011f\u0131m\u0131z makalelerimizde inceledi\u011fimiz AWS Lambda ve Amazon&#46;&#46;&#46;<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":1,"featured_media":26163,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4446,4754,2739,4730],"tags":[4769,4773,4771,4772,4766,4770,4767,4768],"class_list":["post-26157","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-net-6","category-net-7","category-net-core","category-aws","tag-a-request-parameter-based-lambda-authorizer","tag-amazon-resource-name","tag-apigatewaycustomauthorizerrequest","tag-apigatewaycustomauthorizerresponse","tag-lambda-authorizer","tag-request-authorizer","tag-token-authorizer","tag-token-based-lambda-authorizer"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/26157","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/comments?post=26157"}],"version-history":[{"count":21,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/26157\/revisions"}],"predecessor-version":[{"id":26201,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/posts\/26157\/revisions\/26201"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media\/26163"}],"wp:attachment":[{"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/media?parent=26157"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/categories?post=26157"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.gencayyildiz.com\/blog\/wp-json\/wp\/v2\/tags?post=26157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}