标签: basic-authentication

自托管WCF REST服务和基本身份验证

我已经创建了一个自托管的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

11
推荐指数
2
解决办法
1万
查看次数

为什么我的Http客户端在指定凭据时发出2个请求?

我创建了RESTful webservice(WCF),我检查每个请求的凭据.我的一个客户是Android应用程序,服务器端的一切似乎都很棒.我收到请求,如果它有正确的标题 - 我处理它等.

现在我创建了使用此服务的客户端应用程序.这是我做GET的方式:

// Create the web request  
            var request = WebRequest.Create(Context.ServiceURL + uri) as HttpWebRequest;

            if (request != null)
            {
                request.ContentType = "application/json";

                // Add authentication to request  
                request.Credentials = new NetworkCredential(Context.UserName, Context.Password);

                // Get response  
                using (var response = request.GetResponse() as HttpWebResponse)
                {
                    // Get the response stream  
                    if (response != null)
                    {
                        var reader = new StreamReader(response.GetResponseStream());

                        // Console application output
                        var s = reader.ReadToEnd();

                        var serializer = new JavaScriptSerializer();
                        var returnValue = (T)serializer.Deserialize(s, typeof(T)); …
Run Code Online (Sandbox Code Playgroud)

c# http httpwebrequest basic-authentication

11
推荐指数
2
解决办法
5260
查看次数

.htaccess虚拟主机的基本身份验证?

我想知道是否可以根据.htaccess文件中的虚拟主机URL设置条件http基本身份验证要求.

例如,我想要做的是让mysite.com和test.mysite.com在同一目录中运行相同的代码库,但密码保护test.mysite.com.它将以这种方式设置,以便我不需要分支我的代码,因为我的应用程序代码可以看到它从哪个vhost/url服务并选择数据库来提供内容.

apache .htaccess basic-authentication .htpasswd

11
推荐指数
3
解决办法
2万
查看次数

为什么我应该使用HTTP基本身份验证而不是用户名和密码发布参数?

我有一个API端点https://www.example.com/api/authentication,它将用户名和密码作为输入并返回一个身份验证令牌.

在传递用户名和密码方面,我有两个选项(至少),即:

  1. HTTP基本身份验证(将凭据作为HTTP标头的一部分传递)
  2. HTTP POST参数

我知道这两种方法都不提供加密(因此使用HTTPS/SSL).我也理解为什么使用HTTP GET是一个坏主意.

两种方法之间是否存在任何真正的差异(除了基本认证感觉更加惯用)?

basic-authentication

11
推荐指数
1
解决办法
3433
查看次数

Ruby rest-client文件作为具有基本身份验证的多部分表单数据上载

我理解如何使用Ruby的rest-client使用基本身份验证来创建http请求

response = RestClient::Request.new(:method => :get, :url => @base_url + path, :user => @sid, :password => @token).execute
Run Code Online (Sandbox Code Playgroud)

以及如何将文件作为多部分表单数据发布

RestClient.post '/data', :myfile => File.new("/path/to/image.jpg", 'rb')
Run Code Online (Sandbox Code Playgroud)

但我似乎无法弄清楚如何将两者结合起来将文件发布到需要基本身份验证的服务器.有谁知道创建此请求的最佳方法是什么?

ruby post http basic-authentication rest-client

11
推荐指数
1
解决办法
2万
查看次数

如何从basicAuth(Express)注销

我正在尝试使用express设置Web服务器.要访问此服务器,用户必须进行身份验证,为此,我使用Express提供的basicAuth()中间件.它工作得很好,除了我登录后不知道如何注销!我必须关闭我的浏览器以断开连接,但我希望有一个"断开连接"页面,该页面将重定向到"登录"页面(这个页面具有用于登录的可怕形式......).

有没有人有想法?

谢谢你的提前

PS:我为可怜的英语道歉:)

basic-authentication node.js express

11
推荐指数
2
解决办法
1万
查看次数

express.basicAuth抛出错误

我刚刚使用express basic auth在nodejs中创建了基本身份验证

var express = require('express');
var app = express();

// Authenticator
app.use(express.basicAuth('testuser','testpassword'));

app.get('/home', function(req, res) {
 res.send('Hello World');
});

app.listen(process.env.PORT || 8080);
Run Code Online (Sandbox Code Playgroud)

我收到以下错误.我不知道我哪里出错了.

app.use(express.basicAuth('testuser','testpassword'));
                ^
TypeError: Object function createApplication() {
  var app = function(req, res, next) {
    app.handle(req, res, next);
  };

  mixin(app, proto);
  mixin(app, EventEmitter.prototype);

  app.request = { __proto__: req, app: app };
  app.response = { __proto__: res, app: app };
  app.init();
  return app;
} has no method 'basicAuth'
    at Object.<anonymous> (E:\node_modules\npm\login\app.js:5:17)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10) …
Run Code Online (Sandbox Code Playgroud)

basic-authentication node.js

11
推荐指数
1
解决办法
6736
查看次数

带有Authorization标头的JavaScript重定向URL

我设法成功调用Apache中受基本身份验证(htpasswd等)保护的目录后面的URL.Ajax GET请求正常工作并返回受保护的内容:

var encoded = Base64.encode(username + ':' + password);
$.ajax({
    url: "/app/test",
    type: "GET",
    beforeSend: function(xhr) {
        xhr.setRequestHeader('Authorization', 'Basic ' + encoded);
    },
    success: function() {
        window.location.href = '/app/test.html';
    }
});
Run Code Online (Sandbox Code Playgroud)

我最初的假设是,一旦网络会话成功授权了一个请求,它就可以在"成功"块中重定向,而无需询问用户凭据.调用此代码块时,用户已在非受保护环境中输入用户名和密码.但是,当调用重定向时,浏览器将弹出登录/密码窗口.

关于如何预先授权用户提供的基本授权会话的任何建议?

javascript apache jquery basic-authentication

11
推荐指数
1
解决办法
1万
查看次数

ASP.NET MVC5基本HTTP身份验证和AntiForgeryToken异常

我正在开发支持表单身份验证的ASP.NET MVC5项目.Project目前处于测试阶段,并在Azure上进行在线托管,但项目所有者希望禁用对该站点的所有公共访问(因为站点的某些部分根本不需要用户进行身份验证).

在此测试阶段,我们决定从此链接实施基本HTTP身份验证.我已经更改了代码,因此它更符合我的需求:

public class BasicAuthenticationAttribute : FilterAttribute, IAuthorizationFilter
{
    public string BasicRealm { get; set; }

    protected string Username { get; set; }
    protected string Password { get; set; }

    public BasicAuthenticationAttribute(string username, string password)
    {
        this.Username = username;
        this.Password = password;
    }

    public void OnAuthorization (AuthorizationContext filterContext)
    {
        var req = filterContext.HttpContext.Request;
        var auth = req.Headers["Authorization"];
        if (!String.IsNullOrEmpty(auth))
        {
            var cred = System.Text.ASCIIEncoding.ASCII.GetString(Convert.FromBase64String(auth.Substring(6))).Split(':');
            var user = new { Name = cred[0], Pass = cred[1] };

            if …
Run Code Online (Sandbox Code Playgroud)

c# asp.net asp.net-mvc basic-authentication antiforgerytoken

11
推荐指数
1
解决办法
837
查看次数

如何在Spring Boot中使用JWT身份验证实现基本身份验证?

我已经构建了一个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 spring-security basic-authentication jwt spring-boot

11
推荐指数
1
解决办法
2236
查看次数