如何从非 Sitefinity 应用程序向基于 Sitefinity 的站点发送 SSO 声明?

How to send SSO claims to a Sitefinity based site from a non-Sitefinity application?

请帮忙。

如何从非 Sitefinity 应用程序向基于 Sitefinity 的站点发送声明。

我有 Sitefinity 站点用户 login/password 和会员提供商名称。

因此,我需要在浏览器中打开 Sitefinity 站点,并且我的用户已经登录。

我使用以下方法创建令牌:

    private string CreateToken(string name)
                {

                    var key = this.HexToByte("... here is the same hexadecimal code that is specified in SecurityConfug.config file in securityTokenIssuers tag ... ");

                    var sb = new StringBuilder();

// here I'm adding info from claims, only these two claims are needed
                    sb.AppendFormat("{0}={1}&", UrlEncode(ClaimTypes.Name), name);
                    sb.AppendFormat("{0}={1}&", UrlEncode("http://schemas.sitefinity.com/ws/2011/06/identity/claims/domain"), "Default");

                    sb
                        .AppendFormat("TokenId={0}&", UrlEncode(Guid.NewGuid().ToString()))
                        .AppendFormat("Issuer={0}&", UrlEncode("http://localhost"))
                        .AppendFormat("Audience={0}&", UrlEncode("http://localhost"))
                        .AppendFormat("ExpiresOn={0:0}", (DateTime.UtcNow.AddDays(1) - new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc)).TotalSeconds );

                    var unsignedToken = sb.ToString();

                    var hmac = new HMACSHA256(key);
                    var sig = hmac.ComputeHash(Encoding.ASCII.GetBytes(unsignedToken));

                    string signedToken = String.Format("{0}&HMACSHA256={1}",
                        unsignedToken,
                        UrlEncode(Convert.ToBase64String(sig)));

                    return signedToken;    

                }

    private byte[] HexToByte(string hexString)
            {
                byte[] returnBytes = new byte[hexString.Length / 2];
                for (int i = 0; i < returnBytes.Length; i++)
                    returnBytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16);
                return returnBytes;
            }

然后我通过 GET 或 POST 方法将我的令牌作为名为 wrap_access_token 的参数发送。如果我使用 GET 方法,我会使用下面的方法对令牌进行编码。如果我使用POST方法,那么我就不需要另外编码了。

var token = CreateToken(login);
var wrapped_token = UrlEncode(token);
Response.Redirect(baseUrl + "/?wrap_access_token=" + wrapped_token);


    private string UrlEncode(string input)
    {
        var encodedInput = WebUtility.UrlEncode(input);
        encodedInput = Regex.Replace(encodedInput, "(%[0-9A-F]{2})", c => c.Value.ToLowerInvariant());
        return encodedInput;
    }