Last active
February 13, 2016 10:15
-
-
Save niisar/ed185b8dd09cad5a08ae to your computer and use it in GitHub Desktop.
AngularJSAuthentication.API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using AngularJSAuthentication.API.Providers; | |
| using Microsoft.Owin; | |
| using Microsoft.Owin.Security.OAuth; | |
| using Owin; | |
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Web; | |
| using System.Web.Http; | |
| // The “assembly” attribute which states which class to fire on start-up. | |
| [assembly: OwinStartup(typeof(AngularJSAuthentication.API.Startup))] | |
| namespace AngularJSAuthentication.API | |
| { | |
| /// <summary> | |
| /// This class will be fired once server starts. | |
| /// * the “assembly” attribute which states which class to fire on start-up. | |
| /// </summary> | |
| public class Startup | |
| { | |
| /// <summary> | |
| /// * Parameter “IAppBuilder” this parameter will be supplied by the host at run-time. | |
| /// * This “app” parameter is an interface which will be used to compose the | |
| /// application for our Owin server. | |
| /// * “HttpConfiguration” object is used to configure API routes, so we’ll pass | |
| /// this object to method “Register” in “WebApiConfig” class. | |
| /// * “config” object to the extension method “UseWebApi” which will be responsible | |
| /// to wire up ASP.NET Web API to our Owin server pipeline. | |
| /// </summary> | |
| /// <param name="app"></param> | |
| public void Configuration(IAppBuilder app) | |
| { | |
| HttpConfiguration config = new HttpConfiguration(); | |
| ConfiguraOAuth(app); | |
| WebApiConfig.Register(config); | |
| app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll); | |
| app.UseWebApi(config); | |
| } | |
| public void ConfiguraOAuth(IAppBuilder app) | |
| { | |
| OAuthAuthorizationServerOptions OAuthServiceOptions = new OAuthAuthorizationServerOptions() | |
| { | |
| AllowInsecureHttp = true, | |
| TokenEndpointPath = new PathString("/token"), | |
| AccessTokenExpireTimeSpan = TimeSpan.FromDays(10), | |
| Provider = new SimpleAuthorizationServerProvider() | |
| }; | |
| //Token Generation | |
| app.UseOAuthAuthorizationServer(OAuthServiceOptions); | |
| app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions()); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment