尝试从控制台客户端使用ADAL从Azure AD访问令牌时获取异常.
脚步:
ADAL版本使用: Microsoft.IdentityModel.Clients.ActiveDirectory 2.6.0-alpha
控制台应用代码:
void GetToken()
{
clientId = "be6b055a-4efc-222a-2187-49657e6f4f1b";
string ClientKey = "c/uIMlsqn9SzJLKKyBle42Ym+tgcaC2tbMlWxJQawE";
string ClientCredential clientCred = new ClientCredential(clientId, ClientKey);
authenticationContext = new AuthenticationContext("https://login.windows.net/MyDevAD.onmicrosoft.com");
authenticationResult = authenticationContext.AcquireToken("https://mylocalwebapiapp.com/", clientCred);
....
}
Run Code Online (Sandbox Code Playgroud)
================================================== ================================================== ================================================== ==============
小提琴输入:
POST https://login.windows.net/MyDevAD.onmicrosoft.com/oauth2/token HTTP/1.1 Content-Type:application/x-www-form-urlencoded client-request-id:53262b17-1234-4ed9-bdb3- 748d332eb44b return-client-request-id:true x-client-SKU:.NET x-client-Ver:2.6.0.0 x-client-CPU:x64 x-client-OS:Microsoft Windows NT 6.3.9600.0主机:登录. windows.net内容长度:185期望:100-continue连接:Keep-Alive
grant_type = client_credentials&资源= HTTPS%3A%2F%2Flocalhost%3A44307%2F&CLIENT_ID = be6b055a-4efc-408A-8187-42137e6f4f1b&client_secret = C%2FuIMlsqn9SzJLKKyBle123Ym%2BtgcaC3tbMlWxJQawE%3D
================================================== ================================================== ================================================== ============== 小提琴输出:
HTTP/1.1 400 Bad Request …
我在尝试决定接受我所拥有的项目的路线时遇到了问题.
我一直在阅读OWIN规范和.NET中的Katana实现.我之所以选择Katana路由,是因为与ADFS和令牌/ Cookie生成相关的owin组件.
我有两个项目,一个用于MVC 5网站,另一个用于Web API.它们将来可能会停留在两台独立的服务器上,但现在它们是相同的.
我知道我将使用IIS,所以我不需要调查Owin管道.
我的要求是将有使用ADFS登录的用户,以及将使用角色/成员资格提供程序使用令牌/ Cookie生成登录的其他用户.根据谁进行身份验证,我的网页的某些部分将被公开.网页工程师用剃须刀完成.
有没有人有任何我可以阅读的材料来帮助解释我可以采取的设计流程?或者任何人都做了一个类似于我正在经历的项目,可以添加任何建议?有很多不同的文件描述了我需要的特定事物,但不是大局; 比如只讨论WebAPI和ADFS,或WebAPI和windows azure等.
我的理论是在MVC5网站项目上实现认证/授权,在Web API上进行授权(两者之间需要以某种方式进行通信).然后,我可能为ADFS创建项目的副本,并为令牌/ cookie身份验证创建另一个副本?或者我可能需要进行4种不同的身份验证:2对于我在MVC5网站和Web API上进行身份验证的adfs,以及另外2次用于令牌/ cookie生成的身份验证.
任何建议都会有所帮助,因为我对这种技术不是很熟悉.
我成功使用 OneLogin java-saml 库进行 SAML SSO。但 Active Directory 联合身份验证服务 (ADFS) 的 SLO(单点注销)存在问题。该库创建的 LogoutRequest 被 ADFS 拒绝,但被 SimpleSAMLphp IdP 接受。我在创建 LogoutRequest 时通过了这两者nameId,并sessionIndex在响应中从 ADFS 接收到了这些信息。
以下是生成的请求和收到的响应:
验证请求:
<samlp:AuthnRequest xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" ID="ONELOGIN_a80567d6-8957-482b-90e9-99d1b40ec8b1" Version="2.0" IssueInstant="2017-05-31T15:43:07Z" ProviderName="My Company Service Provider" Destination="https://wintest.mycompany.test/adfs/ls/" ProtocolBinding="urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST" AssertionConsumerServiceURL="https://localhost:8443/builder/login_check_sso">
<saml:Issuer>http://localhost:4568/sso/saml/metadata</saml:Issuer>
<samlp:NameIDPolicy Format="urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified" AllowCreate="true" />
<samlp:RequestedAuthnContext Comparison="exact">
<saml:AuthnContextClassRef>urn:oasis:names:tc:SAML:2.0:ac:classes:Password</saml:AuthnContextClassRef>
</samlp:RequestedAuthnContext>
</samlp:AuthnRequest>
Run Code Online (Sandbox Code Playgroud)
回复:
<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" Consent="urn:oasis:names:tc:SAML:2.0:consent:unspecified" Destination="https://localhost:8443/builder/login_check_sso" ID="_f5ea3a59-92f9-4b22-aaf0-36ed392df051" InResponseTo="ONELOGIN_a80567d6-8957-482b-90e9-99d1b40ec8b1" IssueInstant="2017-05-31T15:43:10.158Z" Version="2.0">
<Issuer xmlns="urn:oasis:names:tc:SAML:2.0:assertion">http://wintest.mycompany.test/adfs/services/trust</Issuer>
<samlp:Status>
<samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success" />
</samlp:Status>
<Assertion xmlns="urn:oasis:names:tc:SAML:2.0:assertion" ID="_6f6daef8-f0b5-4437-8e35-ae44ffc48cfe" IssueInstant="2017-05-31T15:43:10.158Z" Version="2.0">
<Issuer>http://wintest.mycompany.test/adfs/services/trust</Issuer>
<ds:Signature xmlns:ds="http://www.w3.org/2000/09/xmldsig#">
<ds:SignedInfo>
<ds:CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#" /> …Run Code Online (Sandbox Code Playgroud) 有一个用户存储,即内部部署AD.ADFS为SharePoint 2013和Power BI提供身份验证.
自定义Web应用程序需要从AD验证用户.Web应用程序后端还需要访问SharePoint REST API.
目标是使用单点登录实现上述目标.如果签入三个应用程序中的任何一个,用户不必输入其他任何一个的凭据.此外,自定义Web应用程序还显示来自SharePoint(iFrame和REST API)和Power BI(iFrame)的内容.
我们尝试了以下两种解决方案,但在任何一种情况下都遇到了问题.
什么不起作用:导航到Power BI或将其包含在iFrame中会将用户重定向到ADFS登录页面.这是因为用户尚未在浏览器中使用ADFS进行身份验证.
什么不起作用:Web应用程序无法使用从ADFS为Web应用程序收到的SAML令牌向SharePoint发出REST API请求.我们已尝试使用该SAML令牌代表登录用户从ADFS for SharePoint请求另一个令牌.这也不起作用.同样,SharePoint 2013内部部署可能不会代表请求接受.
有没有办法为所有三个应用程序提供SSO,同时还可以从Web应用程序获得对SharePoint的REST API访问?用户只需登录一次,最好只登录Web应用程序.
我有一个解决 .NET Core 3.1 预览版 2 的现有 Blazor(服务器)应用程序。
我需要追溯添加本地 ADFS(不是 Azure)安全性。我一直在尝试在 ASP.NET Core 中使用 WS-Federation关注 Microsoft 的Authenticate users,但它顽固地忽略了安全性。这篇文章当然是为 ASP.NET 而写的,而不是 Blazor...
到目前为止我所做的是:
public static void ConfigureServices(IServiceCollection services)
{
services.AddIdentity<IdentityUser, IdentityRole>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders();
services.AddAuthentication()
.AddWsFederation(options =>
{
options.MetadataAddress = "https://adfs.Server.com/FederationMetadata/2007-06/FederationMetadata.xml";
options.Wtrealm = "https://localhost:44323/";
});
services.AddAuthorization();
services.AddRazorPages();
services.AddServerSideBlazor();
....
Run Code Online (Sandbox Code Playgroud)
值得关注的一件事- 数据库中的表当前支持早期的身份验证模式(成员资格?)(由我们正在重写的应用程序使用)。它有表 [AspNetRoles] [AspNetUserClaims] [AspNetUserLogins] [AspNetUserRoles] 和 [AspNetUsers]。这些会被覆盖吗?
public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options)
: base(options)
{
}
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
if …Run Code Online (Sandbox Code Playgroud) authentication authorization adfs asp.net-core blazor-server-side
我的任务是使用来自外部应用程序的 ADFS 令牌对 API 进行身份验证,因此我创建了两个应用程序,一个是 MVC 应用程序,可以说A 使用 SSO 凭据进行身份验证,另一个是 WEB API 应用程序,可以说B,所以在这里从 A,我正在使用 A 的 ADFS 令牌调用 B 的 API,但出现错误。有没有人帮我解决这个问题?
以下是应用程序B中 WEB API 中的代码
ConfigurationManager<OpenIdConnectConfiguration> configManager =
new ConfigurationManager<OpenIdConnectConfiguration>(openIdConfig, new
OpenIdConnectConfigurationRetriever());
OpenIdConnectConfiguration config =
configManager.GetConfigurationAsync().GetAwaiter().GetResult();
result.EmailId = Claims.FirstOrDefault(claim => claim.Type == "upn").Value;
result.WindowsNTId = Claims.FirstOrDefault(claim => claim.Type == "unique_name").Value;
var utc0 = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
result.TokenCreatedOn = utc0.AddSeconds(Convert.ToInt64((Claims.FirstOrDefault(claim =>
claim.Type == "iat").Value)));
result.TokenExpiresOn = utc0.AddSeconds(Convert.ToInt64((Claims.FirstOrDefault(claim =>
claim.Type == …Run Code Online (Sandbox Code Playgroud) 似乎Microsoft ADFSv2支持WS-Trust和SAML Passive,但它构建的WIF堆栈不支持SAML.
WS-Trust和SAML-P有什么区别?它们是否共享相同的安全漏洞,如果是这样,它们是什么?
注意:这里有一个类似但不同的问题:
我将ADFS身份验证添加到具有WebApi后端的Angular SPA网站.为此,我已经使用客户端和RP设置了ADFS实例.
为了登录SPA,用户被重定向到sts.domain/adfs/oauth2/authorize端点.用户在网页上进行身份验证,并重定向到应用程序中的页面 - www.domain/token/redirect.html?code = SOMECODE&state = URL
此页面从URL参数中提取令牌,并调用sts.domain/adfs/oauth2/token端点以获取WebApi后端的JWT令牌.
var url = "https://sts.domain/adfs/oauth2/token";
$.ajax(url, {
type: "POST",
data: {
grant_type: "authorization_code",
client_id: client,
redirect_uri: redirect,
code: token
}
})
Run Code Online (Sandbox Code Playgroud)
然后,应用程序保存WebApi令牌并将其添加到Angular $ http.defaults.headers.common.Authorization,以便它将用于与WebApi后端通信.然后它重定向回SPA.
这一切都可以在IE中正常工作,但在调用/ token OAuth端点时,Firefox和Chrome在标准CORS错误消息中失败.
请求的资源上不存在"Access-Control-Allow-Origin"标头.因此,不允许来源" https://www.domain "访问.
好像我应该将SPA URL添加到ADFS实例的CORS配置中,但我找不到配置ADFS实例的CORS配置的方法.如何在ADFS 3.0 OAuth中配置CORS?有没有不同的方法来完成更标准的任务?
oauth adfs asp.net-web-api angularjs single-page-application
我遇到的情况是我需要访问使用ADFS进行身份验证的ASP.NET Web Api.我可以通过浏览器通过ADFS登录门户网站获取相关的FedAuth cookie,从而可靠地点击它.不幸的是,我需要从专用浏览器外部访问它,以便在移动应用中使用.该项目几乎是为工作和学校认证(内部部署)设置的标准visual studio web api模板的略微修改版本,并设置用于cookie认证.
来自Startup.Auth.cs的一些代码:
public void Configuration(IAppBuilder app)
{
app.SetDefaultSignInAsAuthenticationType(CookieAuthenticationDefaults.AuthenticationType);
app.UseWsFederationAuthentication(
new WsFederationAuthenticationOptions
{
Wtrealm = realm,
MetadataAddress = adfsMetadata
});
app.UseCookieAuthentication(new CookieAuthenticationOptions
{
AuthenticationType = WsFederationAuthenticationDefaults.AuthenticationType
});
}
Run Code Online (Sandbox Code Playgroud)
我似乎无法弄清楚从哪里开始.我已尝试从ADFS请求访问令牌,并可使用相关登录信息获取不同版本的SAML断言,但它会被Web API拒绝.我误解了它应该如何工作吗?
从我的理解,它应该是这样的: 我认为它应该工作
这就是我现在正在试图弄清楚如何获得正确的令牌.
using System;
using System.IdentityModel.Protocols.WSTrust;
using System.IdentityModel.Tokens;
using System.Net;
using System.Net.Http;
using System.ServiceModel;
using System.ServiceModel.Security;
using Thinktecture.IdentityModel.Extensions;
using Thinktecture.IdentityModel.WSTrust;
namespace ConsoleApplication1
{
class Program
{
private const string UserName = "USERNAME";
private const string …Run Code Online (Sandbox Code Playgroud) 我使用passport-saml在节点api中实现了ADFS SSO.登录有效但当我不放弃任何凭据并提交登录表单时,ADFS服务器会返回以下错误:
"SAML提供程序返回响应程序错误:未指定"
当我尝试再次登录后,ADFS直接返回到回调URL并再次弹出错误.
passport.use('saml', new SAMLStrategy({
entryPoint: adfsEntryPoint,
issuer: '{adfs-url}/login/adfs',
callbackUrl: '{adfs-url}/login/adfs/callback',
cert: "{CERT}",
authnContext:'http://schemas.microsoft.com/ws/2008/06/identity/authenticationmethod/windows',
identifierFormat: null,
signatureAlgorithm: 'sha256'
}, (profile, done) => {
const upn = profile["http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn"];
const windowsAccountName = profile["http://schemas.microsoft.com/ws/2008/06/identity/claims/windowsaccountname"];
const user = new userModel.User(upn, "user");
user.enabled = true;
return done(null, user);
}));
passport.serializeUser((user, done) => {
done(null, user);
});
passport.deserializeUser(function (user, done) {
done(null, user);
});
router.get('/auth/adfs', passport.authenticate('saml', { failureRedirect: "/" }), (req, res) => {
res.redirect('/');
});
router.get('/auth/adfs/callback', passport.authenticate('saml', { failureRedirect: "/" }), (req, res) …Run Code Online (Sandbox Code Playgroud) adfs ×10
saml ×3
adfs2.0 ×2
wif ×2
access-token ×1
adal ×1
angularjs ×1
asp.net-core ×1
azure ×1
c# ×1
federation ×1
jwt ×1
katana ×1
oauth ×1
oauth-2.0 ×1
onelogin ×1
owin ×1
passport.js ×1
powerbi ×1
saml-2.0 ×1
sharepoint ×1