目前我正在试图给手机样品应用从官方ADAL github repo转换为caliburn.micro MVVM应用程序。但是有太多的移动部件支持到代码隐藏中以与WebAuthenticationBroker相处,我现在不知道如何在代理完成登录后再次激活应用时如何将其推入视图模型并正确处理导航。由于目前我完全无能为力,因此目前还没有代码可供分享。我在我的Windows Phone 8.1应用程序使用了与MvvmLight沿ADALActive Directory验证库(ADAL)在MVVM手机8.1应用
0
A
回答
0
。你需要做的是一旦你得到一个令牌,你需要使用Messenger模式发送消息。所有需要令牌并且已经订阅的视图模型都会收到它。这是我在我的应用程序中使用MvvmLight所做的事情。请记住,您需要有一个ContinuationManager类和IWebContinuable接口才能使应用程序正常工作。
private async void Login()
{
AuthenticationResult result = null;
context = AuthenticationContext.CreateAsync("https://login.windows.net/<tenant-id>").GetResults();
try
{
//try to check if you can get the token without showing pop-up
result = await context.AcquireTokenSilentAsync("https://management.core.windows.net/", "<clientid>");
if(result.Status==AuthenticationStatus.ClientError)
{
bool exists = CheckInVault();
if(exists)
{
PasswordVault vault = new PasswordVault();
var tokenvault = vault.FindAllByResource("Token");
string RefreshToken = tokenvault[0].Password;
var refresh=await context.AcquireTokenByRefreshTokenAsync(RefreshToken, clientid);
vault.Remove(tokenvault[0]);
StoreToken(refresh);
}
else
{
context.AcquireTokenAndContinue("https://management.core.windows.net/", clientid, WebAuthenticationBroker.GetCurrentApplicationCallbackUri(), StoreToken);
}
}
else if(result != null && result.Status == AuthenticationStatus.Success)
{
// A token was successfully retrieved. Post the new To Do item
bool exists = CheckInVault();
if (exists)
{
PasswordVault vault = new PasswordVault();
var tokenvault = vault.FindAllByResource("Token");
vault.Remove(tokenvault[0]);
}
StoreToken(result);
}
//this method will be called when app is opened first time and pop-up appears
result=await context.AcquireTokenSilentAsync("https://management.core.windows.net/", "<client-id>");
}
catch(Exception e)
{
MessageDialog dialog = new MessageDialog("Error");
}
}
我在做什么这里是 - 获得访问令牌和参考令牌当用户注册首先,我存储刷新令牌在PasswordVault后,以得到它在未来启用单点登录-上。 ADAL实际上使用它的缓存功能,但有时单点登录失败了,因此使用PasswordVault来存储刷新令牌。验证完成后,我有一个委托给StoreToken函数,我实际上存储新的刷新令牌并将访问令牌发送给所有使用MvvmLight中的Messenger类的订户。
private void StoreToken(AuthenticationResult result)
{
try
{
var token = result.AccessToken;
Messenger.Default.Send<string>(token); //send the access token.
PasswordVault vault = new PasswordVault();
PasswordCredential credential = new PasswordCredential();
credential.UserName = result.AccessToken;
credential.Password = result.RefreshToken;
credential.Resource = "Token";
vault.Add(credential);
}
catch(Exception e)
{
}
}
我建议在视图模型中处理导航。定义一个辅助类喜欢的NavigationService:
public class NavigationService:INavigationService
{
private Frame _frame;
public Frame Frame
{
get
{
return _frame;
}
set
{
_frame = value;
_frame.Navigated+= OnFrameNavigated;
}
}
public void NavigateTo(string type)
{
Frame.Navigate(Type.GetType(type));
}
public void GoForward()
{
if (Frame.CanGoForward)
Frame.GoForward();
}
public void GoBack()
{
if (Frame.CanGoBack)
Frame.GoBack();
}
}
从视图模型导航到一个页面,您使用的NavigateTo(string)方法作为
NavigateTo("<fully qualified class name of the page you want to navigate to>,<assembly name>")
我也建议使用IoC容器(MvvmLight为您提供ViewModelLocator类),以便您可以维护视图模型和助手(如NavigationService)的单例实例。我还没有使用过CaliburnMicro框架,但我会假设消息和依赖注入会有类似的功能。
相关问题
- 1. ADAL - AcquireTokenSilentAsync失败(Azure的Active Directory验证库)
- 2. 验证Active Directory用户
- 3. Active Directory组验证性能
- 4. AngularJS组件和ADAL(用于JS的Active Directory Azure库)
- 5. 使用Active Directory进行身份验证
- 6. 使用Active Directory用户验证Oracle数据库
- 7. asp.net中的Azure Active Directory身份验证
- 8. IIS 5.1,Windows身份验证,Active Directory的
- 9. 身份验证与Active Directory不工作
- 10. Tomcat,HTTP身份验证和Active Directory
- 11. Azure Active Directory和联合身份验证
- 12. 如何验证对Active Directory的访问?
- 13. WAS-Active Directory验证失败的原因
- 14. Microsoft Azure Active Directory Passport身份验证
- 15. ASP.NET Active Directory身份验证User.IsInRole
- 16. Intranet与VB.NET的Active Directory身份验证
- 17. Android ADAL Active Directory身份验证库:只允许工作账号,而不是个人微软账号
- 18. 在PHP中使用LDAP进行身份验证通过Active Directory
- 19. 我们可以验证特定组的用户在Active Directory中
- 20. 在Linux上使用Java对Active Directory进行身份验证
- 21. 如何在asp.net中使用Active Directory组进行身份验证?
- 22. 使用Active Directory在C#中进行身份验证
- 23. 在内部网站上使用Active Directory验证
- 24. 使用Azure Active Directory在Azure SQL数据库中进行身份验证B2C
- 25. 使用用户名使用UnboundID验证Active Directory用户
- 26. Active Directory机中的Postgresql
- 27. Active Directory可以使用MD5散列密码验证用户
- 28. 针对Active Directory验证ASP.NET用户:谁管理用户和组?
- 29. 如何使用Active Directory验证当前用户?
- 30. 使用窗体身份验证和Windows身份验证的Active Directory