Ana içeriğe atla

OAuth implementation in Asp.Net Web Api


While desinging Rest API ,we almost need to security layer to keep our data source in safety. The most popular authentication is OAuth in last years.

 What is OAuth ?

OAuth is an authentication which allow to use RestApi Architecture more secure. There are several type of usage which is seperated with GrantTypes as follow;

Grant Types
 - Authorization Code
 - Implicit
 - Password
 - Client Credentials
 - Device Code
 - Refresh Token

We will explain to usage of Password Grant Type and implement in via Asp.Net Web Api.


So lets follow the basic steps to implement password grant type OAuth2:
 - Create a Visual Studio Project as Asp.Net Web Api project.
 - As default we have a ValuesController which allow to call http get :  http://localhost:3221/api/values without any security control.
 - Lets call  http://localhost:3221/api/values url to see data before implement anything.
 - Add new item in App_Start folder as Startup.cs.
 - Add the following codes into Startup File configuration method.


    public void Configuration(IAppBuilder app)
        {
            HttpConfiguration httpConfiguration = new HttpConfiguration();

            this.ConfigureAuth(app);
            WebApiConfig.Register(httpConfiguration);
            app.UseWebApi(httpConfiguration);

        }



        private void ConfigureAuth(IAppBuilder appBuilder)
        {

            OAuthAuthorizationServerOptions oAuthAuthorizationServerOptions = new OAuthAuthorizationServerOptions()
            {
                TokenEndpointPath = new PathString("/api/token"),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
                AllowInsecureHttp = true,
                Provider = new ICRONClientAuthorizationServerProvider()
            };

            //fill the settings for OAuth to create new token properly
            appBuilder.UseOAuthAuthorizationServer(oAuthAuthorizationServerOptions);
            appBuilder.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());

        }


 - Create folder in root as OAuth then add new class into this directory as Provider

resource:
https://oauth.net/2/grant-types/

Bu blogdaki popüler yayınlar

Cannot resolve the collation conflict between "Turkish_CI_AS" and "SQL_Latin1_General_CP1_CI_AS" in the equal to operation.

iki ayrı veri tabanı içindeki tablolar ile işlem yapılmak istendiğinde eğer dil sorunu çıkıyor ise sorgumuzun sonuna 'COLLATE TURKISH_CI_AS' sözcüğünü ekleyerek sorunu çözebiliriz.Örnek : SELECT * FROM veritabani1.dbo.URUN u1 INNER JOIN veritabani2.dbo.URUNLER u2 ON u1.kod = u2.kod COLLATE TURKISH_CI_AS umarım faydalı olmuştur.

IEnumerable ile List Arasındaki Farklar

Sık kullandığımız iki tip olan IEnumerable ve List tipleri ile ilgili sürekli kullanılmasına rağmen farkının çok bilinmediğini düşünerek bu konuda kısa bir yazı yazmak istedim. Bakalım aralarında farklar nelermiş. IEnumerable bir interface iken, List yine IEnumerable sınıftan türeyen somut ( concrete) bir sınıftır. Arasındaki Farklar :  IEnumerable  - List e göre iteration çok daha hızlıdır. Performans için kullanılabilir.  - Read Only bir tip olduğu için Add, Remove gibi işlemler yapılamaz, IEnumerable ile sadece iteration, sort, filter gibi işlemler yapılabilir.  - Soyut bir class olduğu için istenen tipe somutlaştırılabilir.  - yield tipi ile birlikte kullanılabilir.(Promise veri döndürme,state-machine liste kullanımı)  - Linq sorguları veri tabanı sorgularınızın cevaplarınızı IEnumerable olarak döndürür, bu size siz ilgili IEnumerable list i iterate edene kadar ilgili sorguyu çalıştırmama performansı verir, böylece ilgili listeyi kullanmaya ihtiyacınız olmadığı bir durumda yada k

Logo (LOJECTS.exe ve LOBJECTS.dll) Register İşlemleri

LOBJECTS.dll register işlemi : başlat-> çalıştır -> cmd yazıp konsole ekranına geçiyoruz REGİSTER İÇİN : regsvr32 logoDosyaYolu\LOBJECTS.dll yazıyoruz ve dll imizi register ediyoruz UNREGISTER İÇİN : regsvr32 -u logoDosyaYolu\LOBJECTS.dll ile de unregister edebiliriz. LOBJECTS.exe register işlemi : başlat-> çalıştır -> cmd yazıp konsole ekranına geçiyoruz REGİSTER İÇİN : logoDosyaYolu\LOBJECTS.exe -REGSERVER yazıyoruz ve LOBJECTS.exe mizi register ediyoruz. UNREGISTER İÇİN : logoDosyaYolu\LOBJECTS.exe -UNREGSERVER yazıyoruz ve LOBJECTS.exe mizi unregister ediyoruz. Umarım yararlı olmuştur.