我正在使用此 GitHub 的 API 为用户(移动应用程序)生成访问令牌,使用本教程:
我正在使用内置网页,因此用户可以使用用户名和密码登录。之后,用户会收到一个可用于访问 GitHub 范围(在我的例子中为个人资料信息)的 access_token。
响应:
{"access_token":"1234token1234", "scope":"user", "token_type":"bearer"}
Run Code Online (Sandbox Code Playgroud)
但是当用户注销应用程序时,我想删除/撤销这个令牌。我怎样才能做到这一点?
我只在这里找到这个答案:
撤销 OAuth 访问令牌会导致 404 Not Found
但这是2013年的,现在不起作用。
关于如何解决这个问题有什么想法吗?(对不起英国人,巴西人在这里o/)
您好,我正在 .Net core 中开发 Web 应用程序。我已经实现了 V2 身份验证。现在我需要添加授权。该要求指出,首先,
收集用户的声明不应该是应用程序的工作,它们应该在用户 JWT 中可用。其次,将根据声明授予申请许可。
下面是我的验证码。
services
.AddAuthentication(o =>
{
o.DefaultScheme = JwtBearerDefaults.AuthenticationScheme;
})
.AddJwtBearer(o =>
{
o.Authority = azureActiveDirectoryOptions.Authority;
o.TokenValidationParameters = new TokenValidationParameters
{
ValidAudiences = new List<string>
{
azureActiveDirectoryOptions.AppIdUri,
azureActiveDirectoryOptions.ClientId
},
};
});
services.AddMvc(options =>
{
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
options.Filters.Add(new AuthorizeFilter(policy));
}).SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
Run Code Online (Sandbox Code Playgroud)
有人可以帮助我添加基于声明的授权吗?任何帮助将不胜感激。谢谢
authorization claims-based-identity jwt azure-active-directory asp.net-core
我正在尝试在 ASP.Net Core 3.0 Web Api 项目中使用基于 cookie 的身份验证。
目前,我的配置服务如下所示:
public void ConfigureServices(IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy("CorsPolicy",
builder => builder.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader());
});
services.AddAuthentication(options =>
{
options.DefaultScheme = "Cookies";
})
.AddCookie("Cookies", options =>
{
options.Cookie.Name = "auth_cookie";
options.Cookie.SameSite = SameSiteMode.None;
options.Events = new CookieAuthenticationEvents
{
OnRedirectToLogin = redirectContext =>
{
redirectContext.HttpContext.Response.StatusCode = 401;
return Task.CompletedTask;
}
};
});
services.AddAuthorization();
services.AddControllers();
}
Run Code Online (Sandbox Code Playgroud)
我的配置方法如下所示:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
app.UseCors("CorsPolicy");
app.UseHttpsRedirection();
app.UseAuthentication();
app.UseAuthorization(); …Run Code Online (Sandbox Code Playgroud) 我已经构建了一个 spa 网站,前端使用 Angular,服务器端使用 asp.net Core Web Api 3.0。
我正在尝试配置 Windows 身份验证,感谢这篇文章到目前为止一切顺利!但是...当 Api 正确返回 401/403 时,CORS 标头会出现问题,cors 标头会丢失。这是一个例子:
General:
Status Code: 403 Forbidden
Remote Address: [::1]:44389
Referrer Policy: no-referrer-when-downgrade
Response-Headers:
Date: Wed, 20 Nov 2019 16:33:57 GMT
Persistent-Auth: true
Server: Microsoft-IIS/10.0
Transfer-Encoding: chunked
X-Powered-By: ASP.NET
Run Code Online (Sandbox Code Playgroud)
这是我使用该属性时生成的[Authorise]。我遇到的问题是,当 CORS 标头丢失时,角度内的状态代码为 0,因此我的 http 拦截器不知道未经授权,并且无法正确处理重定向。
我尝试使用中间件手动添加标头StartUp:
app.Use(async (context, next) =>
{
context.Response.OnStarting(() =>
{
context.Response.Headers.Add("Access-Control-Allow-Origin", "http://localhost:4200");
return Task.FromResult(0);
});
await next();
});
Run Code Online (Sandbox Code Playgroud)
但这不起作用,中间件仍然删除标头。
有趣的是,如果我删除授权属性并在控制器方法中返回 401/403:
[HttpGet]
public IActionResult …Run Code Online (Sandbox Code Playgroud) 我在 dotnet core 3.1 Web api 项目中使用 Swagger Swashbuckle,但无法向请求调用发送承载授权。我在我的ConfigureServices方法中定义了这个:
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo() { Title = "MyApi", Version = "v1" });
// Set the comments path for the Swagger JSON and UI.
var xmlFile = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
var xmlPath = Path.Combine(AppContext.BaseDirectory, xmlFile);
c.IncludeXmlComments(xmlPath);
c.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme
{
Type = SecuritySchemeType.OAuth2,
Flows = new OpenApiOAuthFlows()
{
Password = new OpenApiOAuthFlow()
{
TokenUrl = new Uri("/api/Account/Login", UriKind.Relative),
}
},
In = ParameterLocation.Header,
Name = "Authorization",
Scheme = "Bearer",
}); …Run Code Online (Sandbox Code Playgroud) authorization swagger bearer-token .net-core asp.net-core-webapi
我正在测试 Istio(服务网格)授权和身份验证功能,并进行了一些测试以在微服务环境中实现 JWT。并且文档不清楚对象类型“AuthorizationPolicy”和“RequestAuthentication”之间的区别,
我正在尝试在我创建的自定义授权处理程序中使用 EnableRewind 方法,但收到错误“'HttpRequest' 不包含 'EnableRewind' 的定义”,我需要访问其中的正文,但如果我这样做代码中显示我在控制器中收到错误“输入不包含任何 JSON 令牌。期望输入以有效的 JSON 令牌开头,....”这是我的处理程序,我从启动文件注入了 IHttpContextAccessor
public class ForPrivateProfileBodyMustOwnRecordOrShouldBeInAdminRoleHandler : AuthorizationHandler<ForPrivateProfileBodyMustOwnRecordOrShouldBeInAdminRole>
{
private readonly IHttpContextAccessor _httpContextAccessor;
public ForPrivateProfileBodyMustOwnRecordOrShouldBeInAdminRoleHandler(IHttpContextAccessor httpContextAccessor)
{
_httpContextAccessor = httpContextAccessor;
}
protected override Task HandleRequirementAsync(AuthorizationHandlerContext context,
ForPrivateProfileBodyMustOwnRecordOrShouldBeInAdminRole requirement)
{
var reader = new System.IO.StreamReader(_httpContextAccessor.HttpContext.Request.Body);
var body = reader.ReadToEndAsync().Result;
//this line is producing error
var req = _httpContextAccessor.HttpContext.Request.EnableRewind();
var request = Newtonsoft.Json.JsonConvert.DeserializeObject<PrivateProfileModel>(body);
var ownerId = context.User.Claims.FirstOrDefault(c => c.Type == "sub")?.Value;
if (request.UserId.ToString() != ownerId && !context.User.IsInRole("Admin"))
{
context.Fail();
return Task.CompletedTask;
}
//all checks …Run Code Online (Sandbox Code Playgroud) 我想使用 Dio 在我的发布请求的授权标头中设置一个令牌。我尝试使用两个选项设置标题。而且两者都不起作用。第一种方式会引发错误,第二种方式不会将数据发送到服务器。从共享首选项添加授权令牌并将其作为发布请求上的标头发送的最佳方法是什么Dio()
当用户登录并访问它时,我将令牌保存在 SharedPreference 上:
String token = "";
@override
void initState() {
getToken();
}
void getToken() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
token = prefs.getString("token");
setState((){});
}
Run Code Online (Sandbox Code Playgroud)
第一种方法用于发送带有标头的数据:
Future<FormsModel> createEntry(
String id,
String formName,
String dataContent,
String dateCreated,
String dateUpdated,
String userLocation,
String imeI,
String updatedBy) async {
String apiUrl = "http://10.0.2.2:8080/api/v1/entry";
Dio().options.headers["Authorization"] = "Bearer $token";
await Dio().post(apiUrl, data: {
"id": id,
"formName": formName,
"dataContent": dataContent,
"dateCreated": dateCreated,
"dateUpdated": dateUpdated,
"userLocation": userLocation,
"imeI": imeI,
"updatedBy": updatedBy …Run Code Online (Sandbox Code Playgroud) 使用 ASP.NET 5,我实现了一个授权策略,我希望将其应用于命名空间中的所有控制器,但不适用于项目中的所有控制器。[Authorize(Policy="MyPolicy")]除了分别向每个控制器添加属性之外,还有其他方法可以做到这一点吗?我想避免另一个开发人员向命名空间添加新控制器但忘记应用策略的风险。
手动执行时看起来像这样:
[ApiController]
[Authorize(Policy="MyPolicy")]
[Route("api/DoStuff")]
public class MyController : ControllerBase
{
[HttpGet("foo")]
public GetFoo()
{
}
}
Run Code Online (Sandbox Code Playgroud) asp.net authorization asp.net-authorization asp.net-core asp.net-core-webapi
如果我x-hasura-admin-secret在仪表板中禁用,然后添加Authorization: Bearer a_jwt_encoded_with_a_HASURA_GRAPHQL_JWT_SECRET_and_the_hasura_custom_claims
然后我不断收到这些 toast 通知:
Schema introspection query failed
x-hasura-admin-secret/x-hasura-access-key required, but not found
Run Code Online (Sandbox Code Playgroud)
我缺少什么?如何在 Hasura GraphiQL 浏览器中测试我的权限等?
我的HASURA_GRAPHQL_JWT_SECRET可能是在错误的地方。我在 Heroku 中设置了它(按照你以前必须做的方式)。
我已经更新了HASURA_GRAPHQL_JWT_SECRETHasura 项目控制台的环境变量中定义的,并将其更新为
{
"key": "01234567890123456789012345678912",
"type": "HS256"
}
Run Code Online (Sandbox Code Playgroud)
但是当我从该配置生成 JWT 并尝试它时,它会抛出相同的 toast 通知......
authorization ×10
asp.net-core ×3
.net-core ×1
access-token ×1
android ×1
angular ×1
asp.net ×1
bearer-token ×1
c# ×1
cors ×1
dart ×1
flutter ×1
github ×1
graphql ×1
hasura ×1
hasura-jwt ×1
istio ×1
java ×1
jwt ×1
kubernetes ×1
swagger ×1