3

私のアプリケーションでは、ユーザーがドロップボックスにサインインできるようにしており、プロセスが完了すると、SessionAuthenticationModule を使用して fedauth Cookie にクレームを書き込みます。

    var sam = FederatedAuthentication.SessionAuthenticationModule;
    if (sam != null)
    {

       // (ClaimsPrincipal.Current.Identity as ClaimsIdentity).AddClaim(new Claim("Provider", "Dropbox"));

        var cp = new ClaimsPrincipal(new ClaimsIdentity(new List<Claim> { new Claim("Provider", "Dropbox") }, "OAuth"));

        var transformer = FederatedAuthentication.FederationConfiguration.IdentityConfiguration.ClaimsAuthenticationManager;
        if (transformer != null)
        {

            cp = transformer.Authenticate(String.Empty, cp);
        }
        var token = new SessionSecurityToken(cp);
        sam.WriteSessionTokenToCookie(token);                       

    }

クレームが書き込まれ、新しいリクエストが行われると、ユーザーが認証され、クレームが機能します。

私の問題は、ユーザーが次のいずれかのログイン URL に移動して、Azure ACS で認証プロセスを開始した場合です。

https://s-innovations.accesscontrol.windows.net/v2/metadata/identityProviders.js?protocol=wsfederation&realm=http://77.75.160.102:2638/&version=1.0&callback=ShowSigninPage

STS がサイトに戻ったときに例外が発生します。

The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. 

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace: 


[FormatException: The input is not a valid Base-64 string as it contains a non-base 64 character, more than two padding characters, or an illegal character among the padding characters. ]
   System.Convert.FromBase64_Decode(Char* startInputPtr, Int32 inputLength, Byte* startDestPtr, Int32 destLength) +10545309
   System.Convert.FromBase64CharPtr(Char* inputPtr, Int32 inputLength) +130
   System.Convert.FromBase64String(String s) +41
   System.IdentityModel.Services.ChunkedCookieHandler.ReadInternal(String name, HttpCookieCollection requestCookies) +350
   System.IdentityModel.Services.ChunkedCookieHandler.ReadCore(String name, HttpContext context) +45
   System.IdentityModel.Services.CookieHandler.Read(String name, HttpContext context) +74
   System.IdentityModel.Services.SessionAuthenticationModule.TryReadSessionTokenFromCookie(SessionSecurityToken& sessionToken) +126
   System.IdentityModel.Services.SessionAuthenticationModule.OnAuthenticateRequest(Object sender, EventArgs eventArgs) +116
   System.Web.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +136
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +69

プロセスが逆の場合は、最初に Azure ACS でログインし、次に dropbox でログインします。物事はうまくいきます。Dropbox クレームが Azure ACS クレームを上書きしています。これにより、SAMを使用してCookieを書き込む最初のコードニペットにエラーがあると思いましたか?

アップデート

MachineKeySessionSecurityTokenHandler を使用しない場合は機能することがわかりました。

  <securityTokenHandlers>
    <!--<add type="System.IdentityModel.Services.Tokens.MachineKeySessionSecurityTokenHandler, System.IdentityModel.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />-->
    <!--<remove type="System.IdentityModel.Tokens.SessionSecurityTokenHandler, System.IdentityModel, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />-->
  </securityTokenHandlers>

MachineKeySessionSecurityTokenHandler をサポートするようにコードを変更する方法を教えてください。

4

2 に答える 2

0

たぶん、Cookie が切り捨てられます。どのブラウザを使用していますか?

于 2012-12-04T12:18:44.693 に答える
0

を使用してSessionAuthenticationModuleを作成しますSessionSecurityToken

var sam = FederatedAuthentication.SessionAuthenticationModule;

var token = sam.CreateSessionSecurityToken(
    claimsPrincipal, 
    "application-context", 
    DateTime.UtcNow, 
    DateTime.UtcNow.AddHours(1), 
    true);

sam.WriteSessionTokenToCookie(token);
于 2013-05-18T20:15:49.527 に答える