2016-07-18 39 views
0

私はADALを使用してユーザーを認証しているアプリを持っています。ログインボタンを押すとサインインページが表示されますが、正しいクレデンシャルを入力しても何も起こりません。認証に必要なすべての変数(共通の権限、リダイレクトURI、クライアントID)を確認しましたが、まだ出ています。Azure Active Directoryでログインが成功した後に認証が行われない

ここでは認証の部分です。

private async Task<bool> AuthenticateUsingADAL(IPlatformParameters parent) 
{ 
    var success = false; 
    try 
    { 
     AuthenticationContext authContext = new AuthenticationContext(CommonAuthority); 
     if (authContext.TokenCache.ReadItems().Count() > 0) 
      authContext = new AuthenticationContext(authContext.TokenCache.ReadItems().First().Authority); 
     AuthResult = await authContext.AcquireTokenAsync(ResourceUri, ClientId, RedirectUri, parent); 
     //i put a WriteLine here but nothing goes through after the AuthResult. I don't know why 

     success = true; 
    } 
    catch (Exception ex) 
    { 
     System.Diagnostics.Debug.WriteLine("Authentication failed " + ex.ToString()); 
    } 
    return success; 
} 

ログイン活動:あなたはキャッシュから物事を読み取ろうとしている。ここ

private void BtnLogin_Click(object sender, EventArgs e) 
{ 
    bool success = false; 

    Task loginTask = new Task(() => 
    { 
     success = SessionsHelper.Login(this); 
    }); 

    loginTask.ContinueWith(t => 
    { 
     if (success) GoToNextActivity(); 
    }, TaskScheduler.FromCurrentSynchronizationContext()); 

    loginTask.Start(); 
} 

答えて

0

:このによって開始された

public bool Login(Activity activity) 
{ 
    bool result = false; 

    if (String.IsNullOrEmpty(Token) || TokenExpired) result = AuthenticateUsingADAL(new PlatformParameters(activity)).Result; 

    return result; 
} 

。コードを次のように変更します。

var authContext = new Microsoft.ADAL.AuthenticationContext(authority); 
authContext.tokenCache.readItems().then(function (items) { 
if (items.length > 0) { 
     authority = items[0].authority; 
     authContext = new Microsoft.ADAL.AuthenticationContext(authority); 
} 
// Attempt to authorize user silently 
authContext.acquireTokenSilentAsync(resourceUri, clientId) 
.then(authCompletedCallback, function() { 
    // We require user cridentials so triggers authentication dialog 
    authContext.acquireTokenAsync(resourceUri, clientId, redirectUri) 
    .then(authCompletedCallback, errorCallback); 
    }); 
}); 
関連する問題