basic-authentication

Get the HTTP Basic Auth username from javascript?

南楼画角 提交于 2019-11-30 12:48:11
I have a webpage that is only accessible over http basic auth. How can I figure out the basic auth username in javascript in that page. i.e. when someone visits it (after logging in), I want to make a popup that says "Hello, you're currently signed in as the user $USERNAME" It's not possible purely from JavaScript. You'd have to have the server side script pick up the username from the request, and insert it in the generated page code for the script to pick up. (eg. <script type="text/javascript">var username= (insert JSON-encoded string here) ;</script> . javascript:window.alert(document

.htaccess basic auth by virtual host?

妖精的绣舞 提交于 2019-11-30 12:07:08
I was wondering if it was possible to setup a conditional http basic auth requirement based on the virtual host URL in an .htaccess file. For example what I want to do is have mysite.com and test.mysite.com run off the same code base in the same directory but password protect test.mysite.com. It would be setup this way so that I wouldn't need to branch my code since my app code can see which vhost/url it's being served from and pick the database to serve content from. You can sort of kludge this by using mod_setenvif along with the mod_auth modules. Use the SetEnvIfNoCase directive to set

Basic Authentication in ASP.NET Core

前提是你 提交于 2019-11-30 10:44:02
Question How can I implement Basic Authentication with Custom Membership in an ASP.NET Core web application? Notes In MVC 5 I was using the instructions in this article which requires adding a module in the WebConfig . I am still deploying my new MVC Core application on IIS but this approach seems not working. I also do not want to use the IIS built in support for Basic authentication , since it uses the Windows credentials. ASP.NET Security will not include Basic Authentication middleware due to its potential insecurity and performance problems. If you require Basic Authentication middleware

How can I retrieve Basic Authentication credentials from the header?

ぃ、小莉子 提交于 2019-11-30 10:15:32
问题 I am trying to write some simple tests User Authentication mechanism which uses Basic Authentication. How can I retrieve the credentials from the header? string authorizationHeader = this.HttpContext.Request.Headers["Authorization"]; Where do I go from here? There are several tutorials but I new to .NET and authentication, could you explain in your answer exactly step-by-step the what and why you are doing. 回答1: From my blog: This will explain in detail how this all works: Step 1 -

asp mvc 3 ActionFilter for basic authentication

安稳与你 提交于 2019-11-30 10:05:07
I have an ASP MVC3 restful service that uses basic authentication. After searching stack overflow, I created the following code. public class BasicAuthentication : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { var req = filterContext.HttpContext.Request; if (String.IsNullOrEmpty(req.Headers["Authorization"])) { filterContext.Result = new HttpNotFoundResult(); } else { var credentials = System.Text.ASCIIEncoding.ASCII .GetString(Convert.FromBase64String(req.Headers["Authorization"].Substring(6))) .Split(':'); var user = new { Name =

Passing basic auth credentials with every request with HtmlUnit WebClient

不想你离开。 提交于 2019-11-30 09:51:21
I'm trying to write a simple smoke test for a web application. The application normally uses form based authentication, but accepts basic auth as well, but since the default is form based authentication, it never sends an authentication required, but instead just sends the login form. In the test I try to send the basic auth header using WebClient webClient = new WebClient(); DefaultCredentialsProvider creds = new DefaultCredentialsProvider(); // Set some example credentials creds.addCredentials("usr", "pwd"); // And now add the provider to the webClient instance webClient

How to allow “/api/**” through my basic auth config and into my oauth config in Spring Security

时光怂恿深爱的人放手 提交于 2019-11-30 09:44:24
问题 I have an app that uses both Basic Auth and OAuth2. Some URLs are authorized using Basic Auth and "/api/**" is authorized using OAuth2. Currently, I have two Java config files ( WebSecurityConfigurerAdapter and ResourceServerConfigurerAdapter ) Each of the config files define a public void configure(HttpSecurity http) method. The trouble I'm having is that I need an elegant way to tell my app whether to use basic auth or oauth2 given the url request. Currently I'm using requestMatchers to

Set Basic HTTP Authentication in Casablanca

随声附和 提交于 2019-11-30 09:04:14
I'm trying to modify the Casablanca tutorial to include basic HTTP authentication to access the Prosper API : auto fileStream = std::make_shared<ostream>(); // Open stream to output file. auto requestTask = fstream::open_ostream(U("results.html")).then([=](ostream outFile) { *fileStream = outFile; // Create http_client to send the request. http_client_config config; credentials creds( "username", "password" ); config.set_credentials( creds ); http_client client( U( "https://api.prosper.com/" ), config ); // Build request URI and start the request. uri_builder builder(U("/api/Listings/"));

HTTPClient sends out two requests when using Basic Auth?

蹲街弑〆低调 提交于 2019-11-30 08:41:10
I have been using HTTPClient version 4.1.2 to try to access a REST over HTTP API that requires Basic Authentication. Here is client code: DefaultHttpClient httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager()); // Enable HTTP Basic Auth httpClient.getCredentialsProvider().setCredentials( new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), new UsernamePasswordCredentials(this.username, this.password)); HttpHost proxy = new HttpHost(this.proxyURI.getHost(), this.proxyURI.getPort()); httpClient.getParams().setParameter(ConnRouteParams.DEFAULT_PROXY, proxy); When I construct a

How can I use Basic HTTP Authentication in PHP?

假装没事ソ 提交于 2019-11-30 08:40:06
I'm trying to use Basic HTTP Authentication and followed the example on the PHP manual page. But it doesn't work for me. The variable $_SERVER['PHP_AUTH_USER'] doesn't seem to be set. When a user try to log in, the user is prompted whith a new login-dialog. The server is running PHP 5.3.3 and I have tried with Google Chrome and Internet Explorer. Here is the simple example that I used: <?php if (!isset($_SERVER['PHP_AUTH_USER'])) { header('WWW-Authenticate: Basic realm="Jonas Realm"'); header('HTTP/1.0 401 Unauthorized'); echo 'User pressed Cancel'; exit; } else { echo "<p>Hello {$_SERVER['PHP