Authorization in ASP.NET Core. Always 401 Unauthorized for [Authorize] attribute

At the request of others here is the answer: The problem was with the middleware order in Startup.cs public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { ConfigureAuth(app); // your authorisation configuration app.UseMvc(); } Why middleware order is important? If we put app.UseMvc() first – then the MVC actions would get in the routing and … Read more

asp.net mvc decorate [Authorize()] with multiple enums

Here is a simple and elegant solution which allows you to simply use the following syntax: [AuthorizeRoles(MyEnum.Admin, MyEnum.Moderator)] When creating your own attribute, use the params keyword in your constructor: public class AuthorizeRoles : AuthorizeAttribute { public AuthorizeRoles(params MyEnum[] roles) { … } protected override bool AuthorizeCore(HttpContextBase httpContext) { … } } This will allow … Read more

Granting access to IIS 7.5 ApplicationPoolIdentity [duplicate]

Ok I have the solution: When using “ApplicationPoolIdentity” with IIS 7.5 the corresponding user is (a virtual system user): “IIS AppPool\<AppPoolName>” You can grant this user permissions and check security setting by searching for this user. See the full explanation here: http://www.iis.net/learn/manage/configuring-security/application-pool-identities

How can I make a request with a bearer token in Go

For control over HTTP client headers, redirect policy, and other settings, create a Client: package main import ( “io/ioutil” “log” “net/http” ) func main() { url := “https://api.globalcode.com.br/v1/publico/eventos” // Create a Bearer string by appending string access token var bearer = “Bearer ” + <ACCESS TOKEN HERE> // Create a new request using http req, … Read more

Authorizing and handshaking with Socket.IO

Edit: In Socket.IO 1.0, middleware is now used. Authorization can be done like so: io.use(function(socket, next) { var handshake = socket.request; next(); }); If you were to need to reject the socket, just pass an error object to the next() callback. The same thing can be done with namespaces: io.of(‘/namespace’).use(function(socket, next) { var handshake = … Read more

Spring Security: mapping OAuth2 claims with roles to secure Resource Server endpoints

After messing around a bit more, I was able to find a solution implementing a custom jwtAuthenticationConverter, which is able to append resource-specific roles to the authorities collection. http.oauth2ResourceServer() .jwt() .jwtAuthenticationConverter(new JwtAuthenticationConverter() { @Override protected Collection<GrantedAuthority> extractAuthorities(final Jwt jwt) { Collection<GrantedAuthority> authorities = super.extractAuthorities(jwt); Map<String, Object> resourceAccess = jwt.getClaim(“resource_access”); Map<String, Object> resource = null; Collection<String> … Read more

How to scrape a website that requires login first with Python

This works for me: ##################################### Method 1 import mechanize import cookielib from BeautifulSoup import BeautifulSoup import html2text # Browser br = mechanize.Browser() # Cookie Jar cj = cookielib.LWPCookieJar() br.set_cookiejar(cj) # Browser options br.set_handle_equiv(True) br.set_handle_gzip(True) br.set_handle_redirect(True) br.set_handle_referer(True) br.set_handle_robots(False) br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1) br.addheaders = [(‘User-agent’, ‘Chrome’)] # The site we will navigate into, handling it’s session br.open(‘https://github.com/login’) # … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)