public override async Task Invoke(IOwinContext context) { var header = context.Request.Headers["Authorization"]; if (!string.IsNullOrWhiteSpace(header)) { var authHeader = AuthenticationHeaderValue.Parse(header); if ("Basic".Equals(authHeader.Scheme, StringComparison.OrdinalIgnoreCase)) { var unencoded = Convert.FromBase64String(authHeader.Parameter); string parameter = Encoding.GetEncoding("iso-8859-1").GetString(unencoded); var parts = parameter.Split(':'); string userName = parts[0]; string password = parts[1]; if (userName == "Microsoft" && password == "Day") { var claims = new[] { new Claim(ClaimTypes.Name, userName) }; var identity = new ClaimsIdentity(claims, "Basic"); context.Request.User = new ClaimsPrincipal(identity); } } } await Next.Invoke(context); }
public void Configuration(IAppBuilder app) { app.Map("/core", coreApp => { var factory = Factory.Create(); var opts = new IdentityServerOptions { IssuerUri = "https://idsrv3.com", SiteName = "Thinktecture IdentityServer v3 - preview 1", SigningCertificate = Cert.Load(), Factory = factory, #if DEBUG PublicHostName = "http://localhost:3333" #else PublicHostName = "http://iidsrv3.azurewebsites.net" #endif }; coreApp.UseIdentityServer(opts); });
/// <summary> /// If template and httpMethod are matched by the inbound request then delegate <paramref name="callee"/> will /// be invoked. RouteParams will be extracted from <paramref name="template"/> and /// Any parameters of callee with names that match RouteParams (including those defined by /// other middleware ahead of this) will be passed when callee is Invoked. /// </summary> /// <param name="httpMethod">Http method to match (GET, POST, PUT etc)</param> /// <param name="callee">The delegate method to be invoked with the arguments populated from RouteParams</param> /// <param name="template">Used to construct the template to be matched</param> /// <param name="iab">The appbuilder being extended (this)</param> public static IAppBuilder Route(this IAppBuilder iab, string httpMethod, Delegate callee, string template) { var rt = new[] { new RouteTemplate(template, false) }; return Route(iab, httpMethod, callee, "Invoke", rt); }
/// <summary> /// The most general for of Route to call a method on an object when the route is matched /// </summary> /// <param name="app">The IAppBuilder instance</param> /// <param name="httpMethod">The HTTP method name to match</param> /// <param name="callee">An object implmenting <paramref name="methodName"/> which will be called when the route is matched</param> /// <param name="methodName">The method to call on <paramref name="callee"/></param> /// <param name="template">A string defining the template</param> /// <param name="iab">The appbuilder being extended (this)</param> public static IAppBuilder Route(this IAppBuilder iab, string httpMethod, object callee, string methodName, string template) { var rt = new[]{ new RouteTemplate(template, false)} ; return Route(iab, httpMethod, callee, methodName, rt); }
/// <summary> /// If the request Path matches <paramref name="template"/> and the <paramref name="httpMethod"/> is matched then /// Any components matched in the template are added to the RouteParams /// and the middleware function <paramref name="routeAction"/> is Invoked /// </summary> /// <param name="template">string used to construct a RouteTemplate</param> /// <param name="routeAction">The middleware function that will be called</param> /// <param name="httpMethod">HTTP method to be matched or all methods if null is passed</param> /// <param name="iab">The appbuilder being extended (this)</param> public static IAppBuilder Route(this IAppBuilder iab, string template, AppFunc routeAction, string httpMethod = null) { var rt = new[] { new RouteTemplate(template, false) }; return Route(iab, httpMethod, routeAction, rt); }