【c#-此操作需要IIS集成管道模式.反伪造令牌】教程文章相关的互联网学习教程文章

c# – 你如何拒绝Katana Bearer令牌的身份【代码】

我怎么能拒绝身份?我的类继承自OAuthBearerAuthenticationProvider并且我重写了ValidateIdentity? 我试过设置context.Rejected();或context.SetError();并抛出异常,但我的控制器仍然被调用. OAuthBearerAuthenticationHandler会调用我的类,所以我知道我的设置正确. 我目前的失败代码public void ConfigureAuth ( IAppBuilder app ){// Enable the application to use a cookie to store information for the signed in user// an...

使用我的API中的访问令牌对C#MVC Web应用程序进行身份验证的最佳方法【代码】

我有一个建立在OWIN和Identity之上的API(我遵循教程here).这很好用,我有一个http://my.domain.com/token端点,返回一个承载访问令牌. 我现在正在构建一个MVC我们的应用程序,它将访问API以通过标准的jQuery ajax调用来记录用户.但是一旦调用了http://my.domain.com/token端点并从API返回了访问令牌,我该如何以我的MVC Web应用程序知道用户身份验证的方式存储此值? 我希望我的Web应用程序能够利用MVC身份功能,例如角色,以便我可以执行...

c# – 在引擎盖下的阻止任务中取消令牌【代码】

我有两个按钮来启动和停止TcpListener.private void buttonStartServer_Click(object sender, EventArgs e) {ThreadPool.SetMinThreads(50, 50);IPAddress ipAddress = IPAddress.Parse("127.0.0.1");_listener = new TcpListener(ipAddress, 5000);cancelSource = new CancellationTokenSource();CancellationToken token = cancelSource.Token;var taskListener = Task.Factory.StartNew((t) => Listener(token),token,TaskCreat...

c# – Outlook Exchange Office 365:如何从访问令牌获取电子邮件地址?【代码】

目前,我正在关注这篇文章https://dev.outlook.com/restapi/tutorial/dotnet.一切都很好,期望我无法从访问令牌中检索用户的电子邮件地址.private string GetEmailFromIdToken(string token) {// JWT is made of three parts, separated by a '.' // First part is the header // Second part is the token // Third part is the signature string[] tokenParts = token.Split('.');if (tokenParts.Length < 3) {// Invalid token, r...

c# – 如何刷新Microsoft Graph的令牌【代码】

我使用以下方法连接到Microsoft Graph:public GraphServiceClient GetAuthenticatedClient(string token) {GraphServiceClient graphClient = new GraphServiceClient(new DelegateAuthenticationProvider(async (requestMessage) =>{// Append the access token to the request.requestMessage.Headers.Authorization = new AuthenticationHeaderValue("bearer", token);}));return graphClient; }我在服务器上运行此代码.我正在...

c# – await方法中的取消令牌【代码】

将令牌放在任务的构造函数中有很多原因,如下所述:Cancellation token in Task constructor: why? 使用关键字async / await,这是如何工作的?例如我的代码如下:public async Task MethodAsync(CancellationToken token) {await Method01Async();await Method02Async(); }虽然它是一个异步过程.我很快就使用了“Task.StartNext”或“Task.Run”或“new Task”.为了能够指定我的取消令牌,我该怎么办?解决方法:您不应该在异步方法中...

c# – 将令牌和琐事映射到行号【代码】

我正在尝试使用Roslyn将令牌和琐事映射到行号. 以下是@Kevin Pilch-Bisson帮助下的最新尝试.public class CSharpSlocAnalyser : ISlocAnalyser {public long GetSlocFor(IEnumerable<FileInfo> files, SlocOptions options){var tree = CSharpSyntaxTree.ParseText( @"using /* Blah */System; // Blah public class MyClass {public void MyMethod(){var blah = ""abc"";} }");var root = tree.GetRoot();var walker = new Custom...

c# – AspNet.Security.OpenIdConnect.Server.刷新令牌

据我所知,ASOS支持开箱即用的刷新令牌.要获取刷新令牌,我需要将offline_access范围添加到我的令牌请求中.但他们在哪里储存?如何更改令牌的到期日期或将其删除?如何确定创建哪个用户刷新令牌?解决方法:But where are they stored?默认情况下,它们无处存储:它们是自包含的.只要用于保护刷新令牌的加密密钥仍在ASP.NET数据保护密钥环中,它们就可以由ASOS解密并用于发布新的访问令牌.How can I change expiration date of the toke...

c# – IdentityServer4令牌签名验证【代码】

我有IdentityServer4生成签名的JWT令牌.在我的web api中,我添加了auth中间件来验证这些令牌:app.UseIdentityServerAuthentication(new IdentityServerAuthenticationOptions{Authority = env.IsProduction() ? "https://www.example.com/api/" : "http://localhost/api/",AllowedScopes = { "WebAPI", "firm",IdentityServerConstants.StandardScopes.OpenId,IdentityServerConstants.StandardScopes.Profile },RequireHttpsMetad...

c# – 密码更改后如何使令牌无效【代码】

我正在使用一个使用JWT令牌身份验证的API.我已经创建了一些逻辑来改变用户密码,并使用验证码&这样. 一切正常,密码就会改变.但这里有一个问题:即使用户密码已更改,我在验证时获得了新的JWT令牌……旧令牌仍然有效. 有关密码更改后如何刷新/无效令牌的任何提示? 编辑:我已经知道如何做到这一点,因为我听说你实际上无法使JWT令牌无效.我的想法是创建一个新的用户列,其中包含类似“accessCode”的内容,并将该访问代码存储在令牌中.每...

c# – 验证SWT令牌REST WCF服务【代码】

我目前正在开发一个WPF客户端,它从Windows Azure AppFabric ACS获取SWT令牌.有了这个令牌,我想使用RESTful WCF服务.我使用this tutorial来获取SWT令牌,它完美无缺.在this MSDN tutorial的帮助下,我创建了RESTful WCF服务. 问题是令牌可能具有错误的格式,因为令牌验证器无法验证它(令牌验证器的IsHMACValid方法中的错误,swtWithSignatur.Length == 1). 与服务器联系的令牌示例: { “appliesTo”: “HTTP://本地主机:7100 /服务/...

c# – 如何在Azure Mobile App中为Xamarin Forms处理用户令牌?

我正在为Azure移动应用程序开发一个带有.NET背景的Xamarin Forms应用程序.我遇到了客户端的一些问题,我想知道如何处理用户令牌MobileServiceUser. 我应该如何保留令牌的数据并通过客户端应用程序使用它? 我成功登录了用户.现在,用户移动到另一个页面并尝试检索信息.我为每个表/对象创建了一个类似“TodoItemManager”的管理器.所以现在我正在使用FoodItemManager,但MobileServiceClient的MobileServiceUser为null,因为我使用Login...

如何将Daemon或Server的Azure AD OAuth2访问令牌和刷新令牌转换为C#ASP.NET Web API【代码】

我已经将Azure AD OAuth2守护程序或服务器实现为ASP.NET Web API.但是我只收到一个访问令牌,它是AuthenticationResult上的属性.见下面的实施.public IHttpActionResult GetAccessToken(string clientId, string clientkey){AuthenticationContext authContext = new AuthenticationContext(authority);ClientCredential clientCredential = new ClientCredential(clientId, clientkey);AuthenticationResult authenticationResult ...

在C#中手动验证JWT令牌【代码】

我在手动验证Identity Server 4发出的JWT令牌时遇到了一些问题.使用 ClientId:“CLIENT1”ClientSecret:“123456” 我不断得到的例外是:IDX10501:签名验证失败.无法匹配键:[PII默认隐藏.将IdentityModelEventSource.cs中的’ShowPII’标志设置为true以显示它.]’ 有人能告诉我哪里出错了.private static void ValidateJwt(string jwt, DiscoveryResponse disco){ var parameters = new TokenValidationParameters{Vali...

c# – Microsoft Graph API令牌的范围与Azure门户中设置的范围不同

通过使用jwt.io我设法确定我的应用程序为Microsoft Graph API获取的令牌只包含Directory.Read.All和User.Read的范围:这与我在Azure门户中设置的权限不同,后者包含更多范围,例如User.ReadBasic.All:有没有什么办法解决这一问题?解决方法:当您回到应用程序并在用户已登录并同意您的应用程序后添加其他权限时,我会看到这种情况.该用户继续获得“旧”权限,但新用户将获得新设置. 如果我的猜测是正确的,那么您最初可能只使用Director...