Javascript事件处理历史[关闭](Javascript Event handling history [closed])
虽然我确实理解Javascript事件的处理方式,但我想了解它背后的完整历史,比如事件处理是如何实际实现的(可能在标记中使用它,如
<a onClick="callFunc()">
)以及它如何更新到其他东西,比如从JS调用它(不显眼的JS)
现在如何使用jQuery实现它?
我只是想了解每个阶段的优势以及事件冒泡/捕获等事情
While I do understand Javascript event handling in bits and pieces, I wanted to understand the complete history behind it, like how event handling was actually implemented (may be using it within the markup like
<a onClick="callFunc()">
)And how it later got updated to something else like calling it from JS (unobtrusive JS)
to how it is implemented now using jQuery ?
I just wanted to understand the advantages at each stage and things like event bubbling/capturing, etc
原文:https://stackoverflow.com/questions/14931727
最满意答案
我使用过滤器属性来装饰我想要向Simple Auth公开的动作。 我不记得我从哪里得到这个代码(可能stackoverflow我只是没有链接所以我不能声称它的功劳)
public class BasicHttpAuthorizeAttribute : AuthorizeAttribute { protected override bool IsAuthorized(HttpActionContext actionContext) { if (Thread.CurrentPrincipal.Identity.Name.Length == 0) { // Get the header value AuthenticationHeaderValue auth = actionContext.Request.Headers.Authorization; // ensure its schema is correct if (auth != null && string.Compare(auth.Scheme, "Basic", StringComparison.OrdinalIgnoreCase) == 0) { // get the credientials string credentials = UTF8Encoding.UTF8.GetString(Convert.FromBase64String(auth.Parameter)); int separatorIndex = credentials.IndexOf(':'); if (separatorIndex >= 0) { // get user and password string passedUserName = credentials.Substring(0, separatorIndex); string passedPassword = credentials.Substring(separatorIndex + 1); SimpleAES crypto = new SimpleAES(); string userName = crypto.DecryptString(ConfigurationManager.AppSettings.Get(Constants.SIMPLEUSERNAME)); string password = crypto.DecryptString(ConfigurationManager.AppSettings.Get(Constants.SIMPLEUSERPASSWORD)); // validate if (passedUserName == userName && passedPassword == password) { Thread.CurrentPrincipal = actionContext.ControllerContext.RequestContext.Principal = new GenericPrincipal(new GenericIdentity(userName, "Basic"), new string[] { }); } } } } return base.IsAuthorized(actionContext); } }
然后我就这样使用它
[BasicHttpAuthorize] public HttpResponseMessage MyExposedSimpleAuthAction()
I us a filter attribute to adorn the actions i wanted to expose to Simple Auth. I cant remember where i got this code from (probably stackoverflow i just don't have the link so i cant claim credit for it)
public class BasicHttpAuthorizeAttribute : AuthorizeAttribute { protected override bool IsAuthorized(HttpActionContext actionContext) { if (Thread.CurrentPrincipal.Identity.Name.Length == 0) { // Get the header value AuthenticationHeaderValue auth = actionContext.Request.Headers.Authorization; // ensure its schema is correct if (auth != null && string.Compare(auth.Scheme, "Basic", StringComparison.OrdinalIgnoreCase) == 0) { // get the credientials string credentials = UTF8Encoding.UTF8.GetString(Convert.FromBase64String(auth.Parameter)); int separatorIndex = credentials.IndexOf(':'); if (separatorIndex >= 0) { // get user and password string passedUserName = credentials.Substring(0, separatorIndex); string passedPassword = credentials.Substring(separatorIndex + 1); SimpleAES crypto = new SimpleAES(); string userName = crypto.DecryptString(ConfigurationManager.AppSettings.Get(Constants.SIMPLEUSERNAME)); string password = crypto.DecryptString(ConfigurationManager.AppSettings.Get(Constants.SIMPLEUSERPASSWORD)); // validate if (passedUserName == userName && passedPassword == password) { Thread.CurrentPrincipal = actionContext.ControllerContext.RequestContext.Principal = new GenericPrincipal(new GenericIdentity(userName, "Basic"), new string[] { }); } } } } return base.IsAuthorized(actionContext); } }
Then i use it as so
[BasicHttpAuthorize] public HttpResponseMessage MyExposedSimpleAuthAction()
相关问答
更多-
所以我终于回过头来再次研究这个问题,事实证明解决方案几乎和我预期的一样简单。 解决方案是拥有两个WebSecurityConfigurerAdapter类。 这在这里描述: http://docs.spring.io/spring-security/site/docs/3.2.x/reference/htmlsingle/#multiple-httpsecurity 这样做有两点需要注意: WebSecurityConfigurerAdapter类必须具有不同的@Order值。 所以我用@Order(1)注 ...
-
将CORS添加到服务器。 pip install django-cors-headers并添加标头也许这个帮助 Add CORS to the server. pip install django-cors-headers and add header maybe this help
-
在我的情况下,似乎重新加载webapp是不够的。 通过FORM身份验证重新启动tomcat后正在使用。 ADD:FORM身份验证使用的是与BASIC / DIGEST不同的摘要算法。 因此,我的旧用户身份验证数据库不可重用。 但这是一个不同的主题。 :) It seems that reloading the webapp was not enough in my case. After restarting tomcat by FORM Authentication is being used. ADD: ...
-
使用Identity Auth的MVC应用程序内的Web API Basic Auth(Web API Basic Auth inside an MVC app with Identity Auth)[2023-05-25]
我使用过滤器属性来装饰我想要向Simple Auth公开的动作。 我不记得我从哪里得到这个代码(可能stackoverflow我只是没有链接所以我不能声称它的功劳) public class BasicHttpAuthorizeAttribute : AuthorizeAttribute { protected override bool IsAuthorized(HttpActionContext actionContext) { if (Thread.C ... -
我应该将auth密钥放入单独的文件中吗? 大概。 作为一般规则,您绝不应将身份验证凭据提交到源存储库。 因此,如果此文件是源控制的,我将提取硬编码值并将其替换为变量。 如何设置该变量取决于您的环境。 通常,从JSON,INI或YML配置文件中读取就足够了。 只需确保将.gitignore(或等效文件)设置为从存储库中排除该配置文件,并确保该文件位于 Web服务器的文档根目录之外,以便无法直接读取。 请注意,如果您已经提交了密钥,那么您将需要对其进行更改,因为其当前值将永久存储在您的存储库历史记录中。 Sho ...
-
试试: SetEnvIf Request_URI ^/(api/|oauth/V2/token) noauth=1 您可以排除uris,只需使用条形分隔它们 Try : SetEnvIf Request_URI ^/(api/|oauth/V2/token) noauth=1 You can exclude uris, just seperate them using a bar |
-
实现它的方法是实现JWT。 使用此插件很容易 按照教程: AngularJS和Laravel应用程序的基于令牌的身份验证 了解JWT: JSON Web令牌的剖析 您还可以使用Auth0 API轻松完成。 它对于小型系统是免费的。 The way to do it is implementing JWT. It is quite easy to make it work with this plugin Follow the tutorial : Token-Based Authentication for ...
-
Xamarin auth和令牌使用ASP.NET MVC身份作为后端(Xamarin auth and tokens using ASP.NET MVC identity as backend)[2024-02-14]
你在那里发布了很棒的资源。 我也使用过它,我已经构建了一个完整的(Xamarin)可移植类库,它可以自动提交每个请求等的令牌。 在ASP.NET MVC中,它就像添加 [Authorize] - 通过API控制器进行分配。 如果你正确地遵循指南,这将立即保护他们。 保护您的API后,您需要发送包含承载令牌的请求。 这是我在我的项目中实现它的方式: // First logging in and getting a token: public async TaskOAuthLoginAsync ... -
好吧,我不喜欢这个解决方案,但它确实有效。 我所做的是检查location指令中的request_uri,如果它以/ api开头,那么我启用auth basic。 我想为此目的使用两个不同的位置,而不是在位置内的if。 这是location指令,默认情况下它已启用,如果请求匹配^ / api /.*$,则auth设置为off: # PROD location ~ ^/app\.php(/|$) { include /etc/nginx/php-mysite.conf; # Protect ...
-
HTTParty基本身份验证 auth = {username: 'user', password: 'pass'} result = HTTParty.get( "https://unicom24.ru/api/partners/requests/v1/locality/", basic_auth: auth ) HTTParty basic auth auth = {username: 'user', password: 'pass'} result = HTTParty.get( ...