我正在设计一个 Erlang/OTP 应用程序,它将通过 RESTful API 公开其服务 (SOA)。
构成后端的服务将是数据库服务、价格计算服务等。
客户端可以有多种类型:Web 客户端、移动客户端、Asterisk 服务器客户端(需要在数据库服务中查找用户记录),甚至是我不打算拥有且还不了解的客户端。客户端将以不同的方式使用 RESTful API:有些将使用所有服务,有些将仅使用部分服务(SOA 方式)。
我主要关心的是身份验证/授权。

我无法使用 Ruby on Rails 的内置身份验证/授权,因为 Web 客户端只是通过 RESTful API 使用应用程序的许多可能客户端中的一个客户端。
所以,我的问题是:
我正在使用ASP.NET Web API和基于自定义令牌的身份验证构建RESTful服务.客户端将在第一次呼叫时发送凭据.该服务将使用用户详细信息创建加密令牌,此标记将从此时开始用于身份验证.现在服务需要将此令牌发送回客户端.最初,我将令牌保存在HTTP自定义响应头中,以便客户端可以独立于服务返回的数据读取值.当客户端和服务位于同一个域中时,这种方法很有效,但在跨域方案中失败.我有CORS启用我的服务并添加了各种标题,如"Access-Control-Expose-Headers","Access-Control-Allow-Origin:*"等.但是跨域客户端无法读取自定义响应头我创建的是"SecureToken:".我在几篇帖子中看到,Web浏览器在跨域方案中读取自定义响应标头时遇到一些问题.所以现在我正在考虑通过服务发送的所有ViewModel /数据对象的公共基类发送安全令牌.
从这个背景来看,我有几个问题:
发送自定义安全令牌的最佳位置是什么.它是响应头还是ViewModel/data类的基类中的公共属性?
是否有一个标准的HTTP响应头,我可以用来发送令牌和自定义信息,以便即使是跨域客户端也可以读取它?
任何帮助将不胜感激!谢谢!
我正在使用身份验证令牌开发 RESTful API。
工作流程简单;客户端执行 /getAuth 请求,发送用户凭据,该凭据返回该用户的令牌。
然后,用户将以下所有请求中的令牌作为标头传递给 API。经过一段时间/多次调用(由服务器决定)后,令牌就会过期。当标头中包含过期令牌的请求到达服务器时,响应状态为401 Unauthorized。在这种情况下,用户必须使用 /getAuth请求另一个令牌,依此类推。
我面临的问题是,当请求因任何其他原因未经授权(访问未经授权的资源)时,API 也会返回 401 Unauthorized。此时,客户端无法知道它是否正在尝试访问他无法访问的内容,或者其用户令牌是否已过期。在没有任何方式知道这一点的情况下,它会再次请求令牌,并重放相同的请求,从而再次得到 401 等等。
所以我的问题是:RESTful API 是否应该为过期令牌返回不同的状态代码或错误消息,而不是为未经授权的请求返回的状态和错误,或者客户端应该找到某种方法来管理它?
我在客户端找到的解决方案是保存每个请求 url,而不是重试因新的(刚刚收到的)令牌而失败的请求。但我觉得它很脏。
我正在使用Rest Assured 来测试API
当我发布身份验证请求时,出现错误:"java.lang.IllegalArgumentException: Cannot serialize because cannot determine how to serialize content-type application/x-www-form-urlencoded;charset=UTF-8"
这是我的测试方法
@Test
public void authenticate()
{
AuthenDto authenDto = new AuthenDto("username","password","false","Login");
given()
.contentType("application/x-www-form-urlencoded;charset=UTF-8")
.accept("application/json, text/plain, */*")
.body(authenDto)
.when()
.post("ENDPOINT")
.then()
.statusCode(200);
}
Run Code Online (Sandbox Code Playgroud) 我正在按照本教程jwt authentication在hapijs v17.2.
我按照教程做了一切,但以下错误让我发疯,甚至调试也没有做出任何改变。
错误
Debug: internal, implementation, error
TypeError: cb is not a function
at Object.secretProvider [as key] (C:\Users\user\WebstormProjects\hapi-blog\node_modules\jwks-rsa\lib\integrations\hapi.js:30:14)
at Object.authenticate (C:\Users\user\WebstormProjects\hapi-blog\node_modules\hapi-auth-jwt2\lib\index.js:123:87)
at module.exports.internals.Manager.execute (C:\Users\user\WebstormProjects\hapi-blog\node_modules\hapi\lib\toolkit.js:35:106)
at module.exports.internals.Auth._authenticate (C:\Users\user\WebstormProjects\hapi-blog\node_modules\hapi\lib\auth.js:242:58)
at authenticate (C:\Users\user\WebstormProjects\hapi-blog\node_modules\hapi\lib\auth.js:217:21)
at module.exports.internals.Request._lifecycle (C:\Users\user\WebstormProjects\hapi-blog\node_modules\hapi\lib\request.js:261:62)
at <anonymous>
Run Code Online (Sandbox Code Playgroud)
应用程序.js
const hapi = require('hapi');
const mongoose = require('./db');
const hapi_auth_jwt = require('hapi-auth-jwt2');
const jwksa_rsa = require('jwks-rsa');
const dog_controller = require('./controllers/dog');
const server = new hapi.Server({
host: 'localhost',
port: 4200
});
const validate_user = (decoded, request, callback) …Run Code Online (Sandbox Code Playgroud) 我领导着一个庞大的 azure 函数开发团队。因此,Microsoft 引用的大多数使用 azure Web 界面的示例对我都不起作用。我正在使用模拟器在本地开发 Azure 函数以节省一些成本。我通过 Visual Studio 将所有功能发布到我的集成环境中。
我正在开发一堆需要 api 网关来处理使用 Azure AD B2C 的身份验证工作流的 azure 函数。现在,没有可以在本地运行的 api 网关模拟器或 Azure AD B2C 模拟器。我的身份验证工作流程涉及拦截对 api 的请求,将它们重定向到 AD B2C 进行身份验证,随后将 auth-token 添加到 http 标头,然后调用 http 触发的 azure 函数。
现在,问题变成了,我如何测试身份验证工作流程?如何设置 api 网关以将我在 Visual Studio 中本地运行的函数注册为云中 api 网关的 api 端点?
restful-authentication azure azure-api-management azure-ad-b2c azure-functions
我用passport包的时候遇到这个错误
在 null 上调用成员函数 createToken()
为什么我会收到这个错误?
这是我的代码:
$users = Users::where('Email' , $username)
->where( 'Password' , $password)
->where('UserStatus' , config('global.active'))
->first();
if($users) {
$success['token'] = $users->createToken('MyApp')->accessToken;
return response()->json(['success' => $success], $this->successStatus);
} else {
return response()->json(['error'=>'Unauthorised'], 401);
}
Run Code Online (Sandbox Code Playgroud) 当我使用护照包时,这样做后,
$success['token'] = $users->createToken('MyApp')->accessToken;
Run Code Online (Sandbox Code Playgroud)
我将处理此代码中的错误:
protected function createRequest($client, $userId, array $scopes)
{
return (new ServerRequest)->withParsedBody([
'grant_type' => 'personal_access',
'client_id' => $client->id,
'client_secret' => $client->secret,
'user_id' => $userId,
'scope' => implode(' ', $scopes),
]);
}
Run Code Online (Sandbox Code Playgroud)
错误文本:
Trying to get property 'id' of non-object
Run Code Online (Sandbox Code Playgroud)
为什么 clinet variabale 为 null ?
我正在启动一个新项目,Firebase Auth 是身份验证的选择。这个想法是通过 Firebase 身份验证创建/登录用户,然后使用 Firebase ID 令牌在我的后端进行身份验证(通过身份验证标头)。
在 Google Samples 中,这是我应该获取令牌的方式:
FirebaseUser mUser = FirebaseAuth.getInstance().getCurrentUser();
mUser.getIdToken(true)
.addOnCompleteListener(new OnCompleteListener<GetTokenResult>() {
public void onComplete(@NonNull Task<GetTokenResult> task) {
if (task.isSuccessful()) {
String idToken = task.getResult().getToken();
// Send token to your backend via HTTPS
// ...
} else {
// Handle error -> task.getException();
}
}
});
Run Code Online (Sandbox Code Playgroud)
但是,如您所见,这是一个异步调用,因为它会转到 Firebase 服务器以获取令牌。所以,每次对后端的 REST API 调用,我都需要运行上面的代码,因为我不知道令牌何时过期。
有没有更好的方法来使用 Firebase Auth 安全调用我的后端 REST API?或者使用 Firebase ID 令牌是最好的一种?如果是这样,我应该如何为每个 REST API 调用包装这个 id 令牌获取?
如果您有更好的方法来验证用户稍后调用 rest apis,我会全力以赴。
api android restful-authentication firebase firebase-authentication
我现在已经为此吵了几天了.
我只是尝试使用基本HTTP身份验证将用户名/密码传递到我的RESTful服务中.其他一切都很棒!
这是我的web.config看起来像:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true">
<add name="UrlRoutingModule" type="System.Web.Routing.UrlRoutingModule, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
</modules>
</system.webServer>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="">
<security mode="Message">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"/>
<standardEndpoints>
<webHttpEndpoint>
<!--
Configure the WCF REST service base address via the global.asax.cs file and the default endpoint
via the attributes on the <standardEndpoint> element below
-->
<standardEndpoint name="" helpEnabled="true" defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true"/>
</webHttpEndpoint>
</standardEndpoints>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceCredentials>
<userNameAuthentication …Run Code Online (Sandbox Code Playgroud) rest ×4
api ×2
laravel ×2
node.js ×2
android ×1
asp.net ×1
azure ×1
azure-ad-b2c ×1
c# ×1
erlang ×1
erlang-otp ×1
firebase ×1
hapijs ×1
http ×1
java ×1
javascript ×1
jwt ×1
rest-assured ×1
security ×1
wcf ×1