本文整理汇总了C#中ILoginService.Authenticate方法的典型用法代码示例。如果您正苦于以下问题:C# ILoginService.Authenticate方法的具体用法?C# ILoginService.Authenticate怎么用?C# ILoginService.Authenticate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ILoginService
的用法示例。
在下文中一共展示了ILoginService.Authenticate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OAuthTokenLoginViewModel
public OAuthTokenLoginViewModel(
ILoginService loginFactory,
IAccountsRepository accountsRepository,
IAlertDialogFactory alertDialogFactory)
{
Title = "Login";
var canLogin = this.WhenAnyValue(y => y.Token, (x) => !string.IsNullOrEmpty(x));
LoginCommand = ReactiveCommand.CreateAsyncTask(canLogin, async _ =>
{
try
{
using (alertDialogFactory.Activate("Logging in..."))
{
var account = await loginFactory.Authenticate(ApiDomain, WebDomain, Token, false);
await accountsRepository.SetDefault(account);
return account;
}
}
catch (UnauthorizedException)
{
throw new Exception("The provided token is invalid! Please try again or " +
"create a new token as this one might have been revoked.");
}
});
LoginCommand.Subscribe(x => MessageBus.Current.SendMessage(new LogoutMessage()));
}
示例2: EnterpriseOAuthTokenLoginViewModel
public EnterpriseOAuthTokenLoginViewModel(
ILoginService loginFactory,
IAccountsRepository accountsRepository,
IAlertDialogFactory alertDialogFactory)
{
Title = "Login";
LoginCommand = ReactiveCommand.CreateAsyncTask(async _ => {
if (string.IsNullOrEmpty(Domain))
throw new ArgumentException("Must have a valid GitHub domain");
if (string.IsNullOrEmpty(Token))
throw new ArgumentException("Must have a valid Token");
Uri domainUri;
if (!Uri.TryCreate(Domain, UriKind.Absolute, out domainUri))
throw new Exception("The provided domain is not a valid URL.");
var apiUrl = Domain;
if (apiUrl != null)
{
if (!apiUrl.EndsWith("/", StringComparison.Ordinal))
apiUrl += "/";
if (!apiUrl.Contains("/api/"))
apiUrl += "api/v3/";
}
try
{
using (alertDialogFactory.Activate("Logging in..."))
{
var account = await loginFactory.Authenticate(apiUrl, Domain, Token, true);
await accountsRepository.SetDefault(account);
return account;
}
}
catch (UnauthorizedException)
{
throw new Exception("The provided token is invalid! Please try again or " +
"create a new token as this one might have been revoked.");
}
});
LoginCommand.Subscribe(x => MessageBus.Current.SendMessage(new LogoutMessage()));
}