public void PreAuthenticate(IRequest req, IResponse res) { var digestAuth = req.GetDigestAuth(); if (digestAuth != null) { //Need to run SessionFeature filter since its not executed before this attribute (Priority -100) SessionFeature.AddSessionIdToRequestFilter(req, res, null); //Required to get req.GetSessionId() using (var authService = req.TryResolve <AuthenticateService>()) { authService.Request = req; var response = authService.Post(new Authenticate { provider = Name, nonce = digestAuth["nonce"], uri = digestAuth["uri"], response = digestAuth["response"], qop = digestAuth["qop"], nc = digestAuth["nc"], cnonce = digestAuth["cnonce"], UserName = digestAuth["username"] }); } } }
public virtual async Task PreAuthenticateWithApiKeyAsync(IRequest req, IResponse res, ApiKey apiKey) { if (RequireSecureConnection && !req.IsSecureConnection) { throw HttpError.Forbidden(ErrorMessages.ApiKeyRequiresSecureConnection.Localize(req)); } ValidateApiKey(req, apiKey); var apiSessionKey = GetSessionKey(apiKey.Id); if (await HasCachedSessionAsync(req, apiSessionKey).ConfigAwait()) { req.Items[Keywords.ApiKey] = apiKey; return; } //Need to run SessionFeature filter since its not executed before this attribute (Priority -100) SessionFeature.AddSessionIdToRequestFilter(req, res, null); //Required to get req.GetSessionId() await using var authService = HostContext.ResolveService <AuthenticateService>(req); var response = await authService.PostAsync(new Authenticate { provider = Name, UserName = "******", Password = apiKey.Id, }).ConfigAwait(); await CacheSessionAsync(req, apiSessionKey); }
public void PreAuthenticate(IRequest req, IResponse res) { //The API Key is sent in the Basic Auth Username and Password is Empty var userPass = req.GetBasicAuthUserAndPassword(); if (userPass != null && string.IsNullOrEmpty(userPass.Value.Value)) { if (RequireSecureConnection && !req.IsSecureConnection) { throw HttpError.Forbidden(ErrorMessages.ApiKeyRequiresSecureConnection); } //Need to run SessionFeature filter since its not executed before this attribute (Priority -100) SessionFeature.AddSessionIdToRequestFilter(req, res, null); //Required to get req.GetSessionId() using (var authService = req.TryResolve <AuthenticateService>()) { authService.Request = req; var apiKey = userPass.Value.Key; var response = authService.Post(new Authenticate { provider = Name, UserName = "******", Password = apiKey, }); } } }
public override void Execute(IRequest req, IResponse res, object requestDto) { //Need to run SessionFeature filter since its not executed before this attribute (Priority -100) SessionFeature.AddSessionIdToRequestFilter(req, res, null); //Required to get req.GetSessionId() req.Items["TriedMyOwnAuthFirst"] = true; // let's simulate some sort of auth _before_ relaying to base class. base.Execute(req, res, requestDto); }
private static void PreAuthenticateWithApiKey(IRequest req, IResponse res, string apiKey) { //Need to run SessionFeature filter since its not executed before this attribute (Priority -100) SessionFeature.AddSessionIdToRequestFilter(req, res, null); //Required to get req.GetSessionId() using (var authService = HostContext.ResolveService <AuthenticateService>(req)) { var response = authService.Post(new Authenticate { provider = Name, UserName = "******", Password = apiKey, }); } }
public void PreAuthenticateWithApiKey(IRequest req, IResponse res, ApiKey apiKey) { if (RequireSecureConnection && !req.IsSecureConnection) { throw HttpError.Forbidden(ErrorMessages.ApiKeyRequiresSecureConnection.Localize(req)); } ValidateApiKey(req, apiKey); var apiSessionKey = GetSessionKey(apiKey.Id); if (SessionCacheDuration != null) { var session = req.GetCacheClient().Get <IAuthSession>(apiSessionKey); if (session != null) { session = HostContext.AppHost.OnSessionFilter(req, session, session.Id); } if (session != null) { req.Items[Keywords.ApiKey] = apiKey; req.Items[Keywords.Session] = session; return; } } //Need to run SessionFeature filter since its not executed before this attribute (Priority -100) SessionFeature.AddSessionIdToRequestFilter(req, res, null); //Required to get req.GetSessionId() using (var authService = HostContext.ResolveService <AuthenticateService>(req)) { var response = authService.Post(new Authenticate { provider = Name, UserName = "******", Password = apiKey.Id, }); } if (SessionCacheDuration != null) { var session = req.GetSession(); req.GetCacheClient().Set(apiSessionKey, session, SessionCacheDuration); } }
public void Register(IAppHost appHost) { appHost.PreRequestFilters.Add((req, res) => { var cultureName = req.GetHeader("X-Culture"); if (string.IsNullOrEmpty(cultureName)) { cultureName = System.Globalization.CultureInfo.CurrentCulture.Name; } var culture = System.Globalization.CultureInfo.GetCultureInfo(cultureName); System.Threading.Thread.CurrentThread.CurrentCulture = culture; System.Threading.Thread.CurrentThread.CurrentUICulture = culture; }); appHost.GlobalRequestFilters.Add((req, res, requestDto) => { SessionFeature.AddSessionIdToRequestFilter(req, res, requestDto); }); }
public virtual void PreAuthenticate(IRequest req, IResponse res) { //API Keys are sent in Basic Auth Username and Password is Empty var userPass = req.GetBasicAuthUserAndPassword(); if (!string.IsNullOrEmpty(userPass?.Value)) { //Need to run SessionFeature filter since its not executed before this attribute (Priority -100) SessionFeature.AddSessionIdToRequestFilter(req, res, null); //Required to get req.GetSessionId() using var authService = HostContext.ResolveService <AuthenticateService>(req); var response = authService.Post(new Authenticate { provider = Name, UserName = userPass.Value.Key, Password = userPass.Value.Value }); } }
public void PreAuthenticate(IRequest req, IResponse res) { //Need to run SessionFeature filter since its not executed before this attribute (Priority -100) SessionFeature.AddSessionIdToRequestFilter(req, res, null); //Required to get req.GetSessionId() var userPass = req.GetBasicAuthUserAndPassword(); if (userPass != null) { var authService = req.TryResolve <AuthenticateService>(); authService.Request = req; var response = authService.Post(new Authenticate { provider = Name, UserName = userPass.Value.Key, Password = userPass.Value.Value }); } }
public void PreAuthenticate(IRequest req, IResponse res) { var user = req.GetUser(); if (user != null) { SessionFeature.AddSessionIdToRequestFilter(req, res, null); //Required to get req.GetSessionId() using (var authService = HostContext.ResolveService <AuthenticateService>(req)) { var session = req.GetSession(); if (LoginMatchesSession(session, user.Identity.Name)) { return; } var response = authService.Post(new Authenticate { provider = Name, UserName = user.GetUserName(), }); } } }
public async Task PreAuthenticateAsync(IRequest req, IResponse res) { var digestAuth = req.GetDigestAuth(); if (digestAuth != null) { //Need to run SessionFeature filter since its not executed before this attribute (Priority -100) SessionFeature.AddSessionIdToRequestFilter(req, res, null); //Required to get req.GetSessionId() using var authService = HostContext.ResolveService <AuthenticateService>(req); var response = await authService.PostAsync(new Authenticate { provider = Name, nonce = digestAuth["nonce"], uri = digestAuth["uri"], response = digestAuth["response"], qop = digestAuth["qop"], nc = digestAuth["nc"], cnonce = digestAuth["cnonce"], UserName = digestAuth["username"] }).ConfigAwait(); } }