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

SQL DATEADD() Fonksiyonu(Sql de tarihe ay,gün,yıl ekleme)

Kullanım Kalıbı : DATEADD (datepart , number , date ) . datepart ksımına month,year,day vs artırmak istediğimiz tarih birimini yazıyoruz. . number ksımına arttırmak istediğimiz miktarı yazıyoruz. . date kısmına da hangi tarih e ekleneceğini belirtiyoruz. Örnek olarak şu an ki tarihten 1 ay sonrasını görmek için : Şu anki tarih '10-1-2011' olsun(gün,ay,yıl) Sorgu : SELECT DATEADD(MONTH,+1,GETDATE()) Çıktı alacağımız tarih : '10-2-2011' şekinde olacaktır.

Netsis NetOpenX50 Nesnesini C# Visual Studio Üzerinde Çalıştırma

Netsis ile sipariş, ürün, fiyat, stok entegrasyonları yaparken NetOpenX apisini kullanmamız gerekiyor. Netsis kullanan bir firma ile entegrasyon geliştirmeden önce yapmamız gereken şey firmanın netopenx api lisansı alıp almadığını öğrenmeliyiz.Bunu onaylattıktan sonra Visual Studio projemize NetOpenx50 dosyasını referans olarak eklemek kalıyor. Projemize referans eklemek için öncelikle NetOpenX50.dll ini bilgisayarımıza indiriyoruz.Ardından komut sataırına girerek aşağıdaki komutu vermeliyiz. regsvr32 C:\Netsis\NetOpenX50.dll Bu işlem sonrasında NetOpenX50 dosyamızı com objesi olarak işletim sistemimize kayıt etmiş oluyoruz. Hemen ardından visual studio projemizi açarak projenin üzerinde References kısmına sağ tuş tıklayarak yeni referens ekle diyoruz.Ardından çıkan pencereden sol panelden COM objelerini seçiyoruz ve orada "NetOpenX50 Kütüphanesi" alanı zaten çıkıyor ve direk seçip referans olarak projemize ekleyebiliyoruz. NetOpenX50 apisinin kullanımı için her d...

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.