作为我正在构建的API的一部分,有一种用户身份验证方法,成功时返回有用的用户信息,API令牌等的有效负载.
在为处理此问题的控制器编写功能测试时,我遇到了测试HTTP Basic auth的问题; 我发现很多博客提到以下代码应该用于欺骗标头以进行身份验证尝试:
@request.env['HTTP_AUTHORIZATION'] = ActionController::HttpAuthentication::Basic.encode_credentials(email, pass)
Run Code Online (Sandbox Code Playgroud)
问题是这没有效果; authenticate_with_http_basic没有看到标题,因此即使存在有效凭据也会返回false.
我错过了什么吗?
请注意,如果在回答中有用,应用程序将被冻结到Rails 2.2.2.
authentication testing ruby-on-rails basic-authentication http-headers
我正在尝试在JUnit测试中使用使用Apache CXF的HTTP基本身份验证的远程Web服务.
我得到的错误是:
javax.xml.ws.WebServiceException: Failed to access the WSDL at: http://localhost:8080/services/MyService?wsdl. It failed with:
Server returned HTTP response code: 401 for URL: http://localhost:8080/services/MyService?wsdl.
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:151)
at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:133)
at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:254)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:217)
at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:165)
at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:93)
at javax.xml.ws.Service.<init>(Service.java:76)
at com.wave2.marketplace.importer.impl.adportal.ws.MyServiceService.<init>(MyServiceService.java:37)
at com.wave2.marketplace.importer.impl.adportal.MyWSTest.testConsumingTheWS(MyWSTest.java:22)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:83)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) …Run Code Online (Sandbox Code Playgroud) 我使用Symfony Standard 2.0.0BETA1并尝试配置http_basic身份验证与本章中的完全相同
security:
encoders:
Symfony\Component\Security\Core\User\User: plaintext
providers:
main:
users:
foo: { password: testing, roles: ROLE_USER }
firewalls:
main:
pattern: /.*
http_basic: true
logout: true
access_control:
- { path: /.*, role: ROLE_USER }
Run Code Online (Sandbox Code Playgroud)
问题是,当我尝试打开一个页面并且我提交用户名"foo"和密码"testing"时,它只是循环并无限地询问我的凭证或显示错误页面.
重现问题的步骤:
预期的行为是查看主页,而是显示凭据提示.
有谁知道为什么会发生这种情况以及如何解决它?
我必须将我的客户从一个网站转移到另一个网站.这发生在客户端.在这第二个网站上,它使用windows基本认证系统.所以它会弹出登录窗口.我需要省略这个弹出窗口并使用javascript在第二个网站上验证我的客户端,然后将他重定向到第二个网站.即使我将凭据放在javascript文件中也没有安全问题,因为整个系统在Intranet中运行.那么如何在第二个网站上验证客户端?
我发现这个线程 如何使用jQuery将Windows身份验证传递给webservice?
但它不起作用.当我查看第二个URL的请求标头时,它不包含Authorization标签.
javascript client-side-scripting windows-authentication basic-authentication single-sign-on
我有一个私人网站,用作来自世界各地的工作人员的内部网站点,他们拥有我的Google Apps域帐户(example.com).他们目前使用OpenId登录各种协作工具,所以我也希望将它用于我的网站.
我想使用Google Apps提供的OpenID登录(而不是基本的HTTP身份验证)保护我的私人会员专用网站上的静态内容.
我知道任何人都可以成为OpenID提供商,所以我想将其限制为一个域名 - 特别是我的Google Apps域名.
目前,我的静态内容是通过nginx提供的.我更喜欢一个简单的nginx模块,它只需要一些设置即可处理.
如果我不得不弄脏,我不介意设置一个基本的Python(比如Django)或Java服务器来处理这个,但我不想使用PHP或Ruby.
openid nginx basic-authentication google-apps static-content
以下代码不对用户进行身份验证(不会发生身份验证失败,但由于缺少权限而导致调用失败):
def remote = new HTTPBuilder("http://example.com")
remote.auth.basic('username', 'password')
remote.request(POST) { req ->
uri.path = "/do-something"
uri.query = ['with': "data"]
response.success = { resp, json ->
json ?: [:]
}
}
Run Code Online (Sandbox Code Playgroud)
但以下工作正常:
def remote = new HTTPBuilder("http://example.com")
remote.request(POST) { req ->
uri.path = "/do-something"
uri.query = ['with': "data"]
headers.'Authorization' =
"Basic ${"username:password".bytes.encodeBase64().toString()}"
response.success = { resp, json ->
json ?: [:]
}
}
Run Code Online (Sandbox Code Playgroud)
为什么不是第一个工作?
我需要提供http-basic-auth一个视图.
我想避免修改中间件设置.
背景:这是一个由远程应用程序填充的视图.
python authentication django http-authentication basic-authentication
我已经创建了一个自托管的WCF REST服务(其中一些来自WCF REST Starter Kit Preview 2).这一切都很好.
我现在正在尝试向服务添加基本身份验证.但是我在WCF堆栈中遇到了一些相当大的障碍,导致我不能这样做.
似乎HttpListener(自托管WCF服务在WCF堆栈中内部使用较低级别)阻止了我WWW-Authenticate在自生成401 Unauthorized响应上插入标头的尝试.为什么?
如果我忘记了这个WWW-Authenticate标题(微软似乎也这样做了),我可以让身份验证工作.但这就是问题所在.如果我没有发回WWW-Authenticate标题,那么Web浏览器将不会显示其标准的"登录"对话框.用户将只面对401 Unauthorized错误页面而无法实际登录.
计算机和人类都应该可以访问REST服务(至少在GET请求级别).因此,我觉得WCF REST在这里并不遵守REST的基本部分.有人同意我的意见吗?
有没有人使用自托管WCF REST服务进行基本身份验证?如果是这样,你是怎么做到的?
PS:显然我打算使用不安全的基本身份验证的前提是我也会为我的服务提供HTTPS/SSL.但那是另一回事.
PPS:我已经尝试过WCF REST Contrib(http://wcfrestcontrib.codeplex.com/),但问题完全相同.看来此库尚未在自托管方案中进行测试.
谢谢.
authentication rest wcf basic-authentication wcf-rest-contrib
我正在尝试修改Casablanca教程以包含访问Prosper API的基本HTTP身份验证:
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/"));
return client.request( methods::GET, builder.to_string() );
})
...
Run Code Online (Sandbox Code Playgroud)
不幸的是,我一直收到错误401 - 未经授权.但是,我可以通过浏览器访问该页面https://username:password@api.prosper.com/api/Listings/,我可以使用Casablanca来访问不需要身份验证的常规网页.
我一般都是REST和Web的新手,文档也没用 - http_client_config"用于设置可能的配置选项".不开玩笑.我甚至不确定我是否使用了正确的课程 - 这些事情看起来很正常.
如何在Casablanca中为http_client请求添加基本身份验证?
我已经构建了一个Spring-Boot使用jwt身份验证的应用程序.
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.diplie</groupId>
<artifactId>rest-api</artifactId>
<version>1.0.0</version>
<packaging>war</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.0.RC1</version>
</parent>
<properties>
<springfox-version>2.2.2</springfox-version>
<java.version>1.8</java.version>
<maven.test.skip>true</maven.test.skip>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>LATEST</version>
</dependency>
<!-- Swagger 2 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>${springfox-version}</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>${springfox-version}</version>
</dependency>
</dependencies>
<dependencyManagement> …Run Code Online (Sandbox Code Playgroud) java ×2
rest ×2
c++ ×1
casablanca ×1
client-side ×1
cxf ×1
django ×1
google-apps ×1
groovy ×1
http-headers ×1
httpbuilder ×1
javascript ×1
jwt ×1
nginx ×1
openid ×1
python ×1
security ×1
spring-boot ×1
symfony ×1
testing ×1
wcf ×1
web-services ×1