/// <summary> /// Sign In User method. /// </summary> /// <param name="username">Username parameter.</param> /// <param name="isPersistent">Is persistent parameter.</param> private void SignInUser(decimal id, string role, string userName, string name, decimal?stateEnrolled, string stateName, string stateShortName, bool isPersistent) { // Initialization. List <Claim> claims = new List <Claim>(); try { // Setting claims.Add(new Claim(ClaimTypes.Name, name)); claims.Add(new Claim(ClaimTypes.Email, userName)); claims.Add(new Claim("StateEnrolled", stateName)); claims.Add(new Claim("StateEnrolledId", Convert.ToString(stateEnrolled))); claims.Add(new Claim(ClaimTypes.NameIdentifier, Convert.ToString(id))); claims.Add(new Claim(ClaimTypes.Role, role)); claims.Add(new Claim("StateShortName", stateShortName)); ClaimsIdentity claimIdenties = new ClaimsIdentity(claims, DefaultAuthenticationTypes.ApplicationCookie); Microsoft.Owin.IOwinContext ctx = Request.GetOwinContext(); IAuthenticationManager authenticationManager = ctx.Authentication; // Sign In. authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, claimIdenties); } catch (Exception ex) { // Info throw ex; } //Thread th = new Thread(CarryOver); //th.Start(); }
private async Task ExecuteQueryBatchAsync( HttpContext context, IServiceProvider services, IReadOnlyList <GraphQLRequest> batch) { IReadOnlyList <IReadOnlyQueryRequest> requestBatch = await BuildBatchRequestAsync(context, services, batch) .ConfigureAwait(false); SetResponseHeaders( context.Response, _streamSerializer.ContentType); var schemaName = await _schemaNameProvider(context).ConfigureAwait(false); var _batchExecutor = _batchExecutorProvider.GetExecutor(schemaName); IResponseStream responseStream = await _batchExecutor .ExecuteAsync(requestBatch, context.GetCancellationToken()) .ConfigureAwait(false); await _streamSerializer.SerializeAsync( responseStream, context.Response.Body, context.GetCancellationToken()) .ConfigureAwait(false); }
protected override bool CanHandleRequest(HttpContext context) { return(string.Equals( context.Request.Method, HttpMethods.Post, StringComparison.Ordinal)); }
private async Task ExecuteOperationBatchAsync( HttpContext context, IServiceProvider services, GraphQLRequest request, IReadOnlyList <string> operationNames) { IReadOnlyList <IReadOnlyQueryRequest> requestBatch = await BuildBatchRequestAsync( context, services, request, operationNames) .ConfigureAwait(false); IResponseStream responseStream = await _batchExecutor .ExecuteAsync(requestBatch, context.GetCancellationToken()) .ConfigureAwait(false); SetResponseHeaders( context.Response, _streamSerializer.ContentType); await _streamSerializer.SerializeAsync( responseStream, context.Response.Body, context.GetCancellationToken()) .ConfigureAwait(false); }
public GeneralWSSession(IReliableStateManager stateManager, Microsoft.Owin.IOwinContext context, IWebSocketSessionManager <IWebSocketSession> factory, CancellationToken cancelToken) : base(stateManager, context, factory, cancelToken) { }
private async Task ExecuteQueryAsync( HttpContext context, IServiceProvider services, GraphQLRequest request) { IReadOnlyQueryRequest queryRequest = await BuildRequestAsync( context, services, QueryRequestBuilder.From(request)) .ConfigureAwait(false); IExecutionResult result = await _queryExecutor .ExecuteAsync(queryRequest, context.GetCancellationToken()) .ConfigureAwait(false); SetResponseHeaders( context.Response, _resultSerializer.ContentType); await _resultSerializer.SerializeAsync( result, context.Response.Body, context.GetCancellationToken()) .ConfigureAwait(false); }
protected async Task <IReadOnlyList <GraphQLRequest> > ReadRequestAsync( HttpContext context) { using (Stream stream = context.Request.Body) { IReadOnlyList <GraphQLRequest> batch = null; switch (ParseContentType(context.Request.ContentType)) { case AllowedContentType.Json: batch = await _requestHelper .ReadJsonRequestAsync( stream, context.GetCancellationToken()) .ConfigureAwait(false); break; case AllowedContentType.GraphQL: batch = await _requestHelper .ReadGraphQLQueryAsync( stream, context.GetCancellationToken()) .ConfigureAwait(false); break; default: throw new NotSupportedException(); } return(batch); } }
public static string GetClientIpAddress(this HttpRequestMessage request) { try { IEnumerable <string> clientIp; string ipAddress = string.Empty; Microsoft.Owin.IOwinContext owinContext = request.GetOwinContext(); if (owinContext != null) { ipAddress = request.GetOwinContext().Request.RemoteIpAddress; if (ipAddress == "127.0.0.1") { if (request.Headers.TryGetValues("X-Forwarded-For", out clientIp)) { ipAddress = clientIp.FirstOrDefault(); } } } return(ipAddress); } catch { return(string.Empty); } }
private static ClaimsPrincipal getOwinUser() { HttpContext context = HttpContext.Current; if (context == null) { throw new Exception("UserHelper: HttpContext.Current is null"); } Microsoft.Owin.IOwinContext owinContext = HttpContext.Current.GetOwinContext(); if (owinContext == null) { throw new Exception("UserHelper: HttpContext.Current.GetOwinContext() is null"); } Microsoft.Owin.Security.IAuthenticationManager authManager = owinContext.Authentication; if (authManager == null) { throw new Exception("UserHelper: HttpContext.Current.GetOwinContext().Authentication is null"); } ClaimsPrincipal user = authManager.User; if (user == null) { throw new Exception("UserHelper: HttpContext.Current.GetOwinContext().Authentication.User is null"); } return(HttpContext.Current.GetOwinContext().Authentication.User); }
public void LogOut() { Microsoft.Owin.IOwinContext owinContext = HttpContext.Current.Request.GetOwinContext(); IEnumerable <AuthenticationDescription> authenticationTypes = owinContext.Authentication.GetAuthenticationTypes(); owinContext.Authentication.SignOut(authenticationTypes.Select(o => o.AuthenticationType).ToArray()); }
public static Task Missing(this Microsoft.Owin.IOwinContext ctx, string name) { ctx.Response.StatusCode = 401; return(ctx.Response.WriteAsync( $"Parameter '{name}' is not specified." )); }
public static Task JSON(this Microsoft.Owin.IOwinContext ctx, object content) { ctx.Response.StatusCode = 200; ctx.Response.ContentType = "application/json"; return(ctx.Response.WriteAsync(JsonConvert.SerializeObject(content))); }
public static Task Error(this Microsoft.Owin.IOwinContext ctx, int code, string description) { ctx.Response.StatusCode = code; ctx.Response.Write(description); return(Task.CompletedTask); }
protected override void Postprocess(Microsoft.Owin.IOwinContext ctx) { if (SignInIdentity != null) { ctx.Authentication.SignIn(SignInIdentity); SignInIdentity = null; } }
/// <summary> /// Construtor padrão. /// </summary> /// <param name="context"></param> public HttpWorkerRequestWrapper(Microsoft.Owin.IOwinContext context) { _owinContext = context; _appPhysPath = System.Threading.Thread.GetDomain().GetData(".appPath").ToString(); _appVirtPath = System.Threading.Thread.GetDomain().GetData(".appVPath").ToString(); _page = context.Request.Uri.LocalPath; ExtractPagePathInfo(); }
public static Task Text(this Microsoft.Owin.IOwinContext ctx, string content) { ctx.Response.StatusCode = 200; ctx.Response.ContentType = "text/plain"; return(ctx.Response.WriteAsync(content)); }
public HttpContext(IDictionary<string, object> environement, IServiceProvider globalServices, IServiceProvider localServices, ISettings settings) { _context = new Microsoft.Owin.OwinContext(environement); _request = new HttpRequest(_context.Request); _response = new HttpResponse(_context.Response); _globalServices = globalServices; _localServices = localServices; _settings = settings; }
public HttpContext(IDictionary <string, object> environement, IServiceProvider globalServices, IServiceProvider localServices, ISettings settings) { _context = new Microsoft.Owin.OwinContext(environement); _request = new HttpRequest(_context.Request); _response = new HttpResponse(_context.Response); _globalServices = globalServices; _localServices = localServices; _settings = settings; }
public ActionResult LogOff() { // We need to remove all session variables between this web app and the client Session.RemoveAll(); // ASP.NET stuff that was here to remove user authorization context. Microsoft.Owin.IOwinContext ctx = Request.GetOwinContext(); Microsoft.Owin.Security.IAuthenticationManager authManager = ctx.Authentication; authManager.SignOut("ApplicationCookie"); return(RedirectToAction("index", "Welcome")); }
//public static IServiceScope GetRequestServiceScope(this Microsoft.Owin.IOwinContext owinContext) //{ // var current = OwinRequestScopeContext.Current; // current.Items.TryGetValue(typeof(IServiceScope).Name, out object scope); // return scope as IServiceScope; //} public static IServiceProvider GetRequestServices(this Microsoft.Owin.IOwinContext owinContext) { var current = OwinRequestScopeContext.Current; current.Items.TryGetValue(HttpContextWrapper.RequestServicesKey, out object spObj); var sp = spObj as IServiceProvider; // var scope = GetRequestServiceScope(owinContext); return(sp); }
public static Task Error(this Microsoft.Owin.IOwinContext ctx, int error = 500) { if (error == 200) { error = 500; } ctx.Response.StatusCode = error; return(Task.CompletedTask); }
public static Task NotAuthorized(this Microsoft.Owin.IOwinContext ctx, string message = null) { ctx.Response.StatusCode = 403; if (!string.IsNullOrWhiteSpace(message)) { ctx.Response.Write(message); } return(Task.CompletedTask); }
protected override async Task Handler(HttpContext context) { if (context.Request.Method == "GET" && context.Request.Path.ToString() == "/ping") { context.Response.StatusCode = 400; } else { await base.Handler(context); } }
public ActionResult ErrorPage() { // Setting. Microsoft.Owin.IOwinContext ctx = Request.GetOwinContext(); IAuthenticationManager authenticationManager = ctx.Authentication; // Sign Out. authenticationManager.SignOut(); return(View()); }
static void Cors(Microsoft.Owin.IOwinContext ctx) { ctx.Response.Headers.Set("Cache-Control", "no-cache, no-store, must-revalidate"); ctx.Response.Headers.Set("Pragma", "no-cache"); ctx.Response.Headers.Set("Expires", "0"); ctx.Response.Headers.Set("Access-Control-Allow-Origin", "*"); ctx.Response.Headers.Set("Access-Control-Allow-Headers", "Accept, Content-Type, Authorization"); ctx.Response.Headers.Set("Access-Control-Allow-Methods", "*"); ctx.Response.Headers.Set("X-Content-Type-Options", "nosniff"); }
static Task JSON(Microsoft.Owin.IOwinContext ctx, string data) { ctx.Response.StatusCode = 200; if (!string.IsNullOrWhiteSpace(data)) { ctx.Response.ContentType = "application/json"; return(ctx.Response.WriteAsync(data)); } return(Task.CompletedTask); }
protected override async Task Handler(HttpContext context) { if (context.Request.Method == "GET" && context.Request.Path.ToString() == "/ping") { await Task.Delay(100); context.Response.StatusCode = (int)HttpStatusCode.OK; } else { await base.Handler(context); } }
protected override void Postprocess(Microsoft.Owin.IOwinContext ctx) { if (SignInIdentity != null) { var props = new Microsoft.Owin.Security.AuthenticationProperties(); props.Dictionary.Add("signin", SignInId); if (SignInIdentity.AuthenticationType == Constants.ExternalAuthenticationType) { props.Dictionary.Add("katanaAuthenticationType", "Google"); } ctx.Authentication.SignIn(props, SignInIdentity); SignInIdentity = null; } }
public ActionResult SignOut() { Microsoft.Owin.IOwinContext OwinContext = HttpContext.GetOwinContext(); OwinContext.Authentication.SignOut(Microsoft.AspNet.Identity.DefaultAuthenticationTypes.ApplicationCookie); if (WebConfigurationManager.AppSettings["LoginMode"] == "SSL") { var returnurl = Server.UrlEncode("http://" + HttpContext.Request.Url.Authority); Response.Redirect(WebConfigurationManager.AppSettings["LoginUrl"] + "Account/LoginOut?returnUrl=" + returnurl + "&systemName=" + WebConfigurationManager.AppSettings["SystemName"]); return(null); } else { return(RedirectToAction("Login", "Account")); } }
/// <summary> /// Construtor padrão. /// </summary> /// <param name="context"></param> public HttpContext(Microsoft.Owin.IOwinContext context, System.Web.HttpRequestBase request, System.Web.HttpResponseBase response) { _request = request; _response = response; _items = new System.Collections.Hashtable(); _items["owin.Environment"] = context; if (Colosoft.Runtime.PlatformHelper.IsRunningOnMono) { System.Web.WebPages.BrowserHelpers.SetOverriddenBrowser(this, "Mozilla/4.0 (compatible; MSIE 6.1; Windows XP)"); } else { System.Web.WebPages.BrowserHelpers.SetOverriddenBrowser(this, System.Web.WebPages.BrowserOverride.Desktop); } }
protected override async Task ExecuteRequestAsync( HttpContext context, IServiceProvider services) { IReadOnlyList <GraphQLRequest> batch = await ReadRequestAsync(context) .ConfigureAwait(false); if (batch.Count == 1) { string operations = context.Request.Query[_batchOperations]; if (operations == null) { await ExecuteQueryAsync(context, services, batch[0]) .ConfigureAwait(false); } else if (TryParseOperations(operations, out IReadOnlyList <string> operationNames)) { await ExecuteOperationBatchAsync( context, services, batch[0], operationNames) .ConfigureAwait(false); } else { // TODO : resources var result = QueryResult.CreateError( ErrorBuilder.New() .SetMessage("Invalid GraphQL Request.") .SetCode(ErrorCodes.Server.RequestInvalid) .Build()); SetResponseHeaders( context.Response, _resultSerializer.ContentType); await _resultSerializer.SerializeAsync( result, context.Response.Body) .ConfigureAwait(false); } } else { await ExecuteQueryBatchAsync(context, services, batch) .ConfigureAwait(false); } }