我们使用证书编写Sharepoint应用程序,将其扩展为提供程序托管,并将我们的MVC项目锚定到它 在Sharepoint展开的同一IIS上展开所有这些。Sharepoint身份验证。如何从ADFS获取SharePoint cookie
任务#1:用户登录Sharepoint,启动我们的应用程序;应用程序启动时没有任何授权请求,并得到从SharePoint它登录的用户
任务#2:如果SharePoint服务请求是必要的,我们在SharePoint应用程序日志中的用户名登录的用户登录SharePoint中。
我们尝试:
1)构建供应商提供托管应用程序,它写我们的MVC,创建自唱证书,调整高信任的SharePoint网站和我们的MVC之间。
我们得到: 如果我们的MVC使用Windows身份验证,然后转移到我们的应用程序时,用户名和密码被要求一遍又一遍;当输入它们时,我们可能使用GetS2SClientContextWithWindowsIdentity
方法得到ClientContext
到TokenHelper
。
如果Windows身份验证被禁用,则用户没有登录请求,这个方法来响应不同的是,用户没有登录。
2) 我们安装和调整ADFS,配置的Sharepoint与ADFS工作,写(-Federtation` WS无源端点在Identifiers and
)SharePoint和我们在继电保护方信任的应用程序的地址
我们得到: 用户登录SharePoint和转移到我们的应用程序时,该啦tter获得用户数据(索赔)
因此,第一项任务已经完成。 之后,授权用户在获得访问SharePoint服务的问题出现
我们试图通过我们收到 索赔获得AccessToken
为SharePoint我们试图传递以下声明:
nii":"trusted:adfs
nii":"urn:office:idp:forms:adfs201 //adfs201 - name of our ADFS service
upn:UserLogin
emailaddress:[email protected]
在那之后,我们叫的方法响应AccessToken
按照输入的索赔
string issuer = string.IsNullOrEmpty(sourceRealm) ? issuerApplication : string.Format("{0}@{1}", issuerApplication, sourceRealm);
string nameid = string.IsNullOrEmpty(sourceRealm) ? sourceApplication : string.Format("{0}@{1}", sourceApplication, sourceRealm);
string audience = string.Format("{0}/{1}@{2}", targetApplication, targetApplicationHostName, targetRealm);
List<JsonWebTokenClaim> actorClaims = new List<JsonWebTokenClaim>();
actorClaims.Add(new JsonWebTokenClaim(JsonWebTokenConstants.ReservedClaims.NameIdentifier, nameid));
if (trustedForDelegation && !appOnly)
{
actorClaims.Add(new JsonWebTokenClaim(TokenHelper.TrustedForImpersonationClaimType, "true"));
}
if (addSamlClaim)
actorClaims.Add(new JsonWebTokenClaim(samlClaimType, samlClaimValue));
// Create token
JsonWebSecurityToken actorToken = new JsonWebSecurityToken(
issuer: issuer,
audience: audience,
validFrom: DateTime.UtcNow,
validTo: DateTime.UtcNow.AddMinutes(TokenLifetimeMinutes),
signingCredentials: SigningCredentials,
claims: actorClaims);
string actorTokenString = new JsonWebSecurityTokenHandler().WriteTokenAsString(actorToken);
if (appOnly)
{
// App-only token is the same as actor token for delegated case
return actorTokenString;
}
List<JsonWebTokenClaim> outerClaims = null == claims ? new List<JsonWebTokenClaim>() : new List<JsonWebTokenClaim>(claims);
outerClaims.Add(new JsonWebTokenClaim(ActorTokenClaimType, actorTokenString));
//****************************************************************************
//SPSAML
if (addSamlClaim)
outerClaims.Add(new JsonWebTokenClaim(samlClaimType, samlClaimValue));
//****************************************************************************
JsonWebSecurityToken jsonToken = new JsonWebSecurityToken(
nameid, // outer token issuer should match actor token nameid
audience,
DateTime.UtcNow,
DateTime.UtcNow.AddMinutes(10),
outerClaims);
string accessToken = new JsonWebSecurityTokenHandler().WriteTokenAsString(jsonToken);
然后,我们试图让ClientContext
,我们荷兰国际集团的方法:
GetClientContextWithAccessToken(targetApplicationUri.ToString(), accessToken);
但我们得到了一个错误报告:
401 Unauthorized
ClientID
和IssureID
写正确的,小写
在那之后,我们决定从ADFS要求SecurityToken
的帮助username
和password
。收到它后,我们请求使用SecurityToken
在SharepointSTS中进行授权。然后,我们的应用程序获得了Cookie Sharepoint,它被锚定到Sharepoint服务的查询(添加到CookieContainer FedAuth
)。当激活ExecutingWebRequest += ClientContext_ExecutingWebRequest
时,发生上述情况。
但是为此,应该使用username
和password
再次请求。
如果我们不SecurityToken
与用户的数据提交username
和password
,然后ADFS回应,其中的应用程序池启动的名下。我们需要登录到SharePoint的用户的SecurityToken
。 我们还试图发出SecurityToken
var session = System.IdentityModel.Services.FederatedAuthentication.SessionAuthenticationModule.CreateSessionSecurityToken(ClientPrincipals, "context", DateTime.UtcNow, System.DateTime.UtcNow.AddHours(1), true);
System.IdentityModel.Services.FederatedAuthentication.SessionAuthenticationModule.AuthenticateSessionSecurityToken(session, true);
但反应不是我们所需要的SharePoint权限相同。
在端点的ADFS中,我们调整URL;我们需要SharePoint授权的SecurityToken (wresult)
通过POST查询发送给它。问题是,我们无法在应用程序中接收到此查询,因为它在状态302中广播,并通过GET方法重定向到我们的应用程序,而我们的Cookie没有SecurityToken
。
现在的问题是:我们怎么能得到SecurityToken
的用户登录SharePoint?