本文整理汇总了C#中Microsoft.Live.LiveAuthClient.InitializeAsync方法的典型用法代码示例。如果您正苦于以下问题:C# LiveAuthClient.InitializeAsync方法的具体用法?C# LiveAuthClient.InitializeAsync怎么用?C# LiveAuthClient.InitializeAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Live.LiveAuthClient
的用法示例。
在下文中一共展示了LiveAuthClient.InitializeAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AuthenticateSilent
/// <summary>
/// Versucht Login, ohne einen entsprechenden Dialog zu zu zeigen.
/// </summary>
/// <returns>Ein MobileServiceUser, der awaited werden kann oder null bei Misserfolg.</returns>
internal static async Task<MobileServiceUser> AuthenticateSilent(MobileServiceClient mobileService)
{
LiveAuthClient liveAuthClient = new LiveAuthClient(APIKeys.LiveClientId);
session = (await liveAuthClient.InitializeAsync()).Session;
return await mobileService.LoginWithMicrosoftAccountAsync(session.AuthenticationToken);
}
示例2: SignOutClick
private async void SignOutClick(object sender, RoutedEventArgs e)
{
try
{
// Initialize access to the Live Connect SDK.
LiveAuthClient LCAuth = new LiveAuthClient();
LiveLoginResult LCLoginResult = await LCAuth.InitializeAsync();
// Sign the user out, if he or she is connected;
// if not connected, skip this and just update the UI
if (LCLoginResult.Status == LiveConnectSessionStatus.Connected)
{
LCAuth.Logout();
}
// At this point, the user should be disconnected and signed out, so
// update the UI.
this.userName.Text = "You're not signed in.";
// Show sign-in button.
signInBtn.Visibility = Windows.UI.Xaml.Visibility.Visible;
signOutBtn.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
}
catch (LiveConnectException x)
{
// Handle exception.
this.userName.Text = x.Message.ToString();
throw new NotImplementedException();
}
}
示例3: SetNameField
private async Task SetNameField(Boolean login)
{
// If login == false, just update the name field.
await App.updateUserName(this.UserNameTextBlock, login);
// Test to see if the user can sign out.
Boolean userCanSignOut = true;
var LCAuth = new LiveAuthClient();
LiveLoginResult LCLoginResult = await LCAuth.InitializeAsync();
if (LCLoginResult.Status == LiveConnectSessionStatus.Connected)
{
userCanSignOut = LCAuth.CanLogout;
}
var loader = new Windows.ApplicationModel.Resources.ResourceLoader();
if (String.IsNullOrEmpty(UserNameTextBlock.Text)
|| UserNameTextBlock.Text.Equals(loader.GetString("MicrosoftAccount/Text")))
{
// Show sign-in button.
SignInButton.Visibility = Visibility.Visible;
SignOutButton.Visibility = Visibility.Collapsed;
}
else
{
// Show sign-out button if they can sign out.
SignOutButton.Visibility = userCanSignOut ? Visibility.Visible : Visibility.Collapsed;
SignInButton.Visibility = Visibility.Collapsed;
}
}
示例4: ensureConnection
private async Task<LiveConnectClient> ensureConnection()
{
if (connection != null)
{
return connection;
}
// Initialize access to the Live Connect SDK.
LiveAuthClient LCAuth = new LiveAuthClient("https://chivalry.azure-mobile.net/");
LiveLoginResult LCLoginResult = await LCAuth.InitializeAsync();
// Sign in to the user's Microsoft account with the required scope.
//
// This call will display the Microsoft account sign-in screen if the user
// is not already signed in to their Microsoft account through Windows 8.
//
// This call will also display the consent dialog, if the user has
// has not already given consent to this app to access the data described
// by the scope.
//
LiveLoginResult loginResult = await LCAuth.LoginAsync(new string[] { "wl.basic", "wl.emails" });
if (loginResult.Status == LiveConnectSessionStatus.Connected)
{
// Create a client session to get the profile data.
connection = new LiveConnectClient(LCAuth.Session);
mobileServiceUser = await App.MobileService.LoginAsync(loginResult.Session.AuthenticationToken);
return connection;
}
if (LoginFailed != null)
{
LoginFailed(this, null);
}
return null;
}
示例5: SignOutClick
private async void SignOutClick(object sender, RoutedEventArgs e)
{
try
{
// Initialize access to the Live Connect SDK.
LiveAuthClient LCAuth = new LiveAuthClient();
LiveLoginResult LCLoginResult = await LCAuth.InitializeAsync();
// Sign the user out, if he or she is connected;
// if not connected, skip this and just update the UI
if (LCLoginResult.Status == LiveConnectSessionStatus.Connected)
{
LCAuth.Logout();
}
// At this point, the user should be disconnected and signed out, so
// update the UI.
this.userName.Text = "You're not signed in.";
Connection.User = null;
// Show sign-in button.
signInBtn.Visibility = Windows.UI.Xaml.Visibility.Visible;
signOutBtn.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
new MessageDialog("The app is exiting since you are no longer logged in.").ShowAsync();
App.Current.Exit();
}
catch (LiveConnectException x)
{
// Handle exception.
}
}
示例6: SignOutButton_OnClick
private async void SignOutButton_OnClick(object sender, RoutedEventArgs e)
{
try
{
// Initialize access to the Live Connect SDK.
LiveAuthClient LCAuth = new LiveAuthClient();
LiveLoginResult LCLoginResult = await LCAuth.InitializeAsync();
// Sign the user out, if he or she is connected;
// if not connected, skip this and just update the UI
if (LCLoginResult.Status == LiveConnectSessionStatus.Connected)
{
LCAuth.Logout();
}
// At this point, the user should be disconnected and signed out, so
// update the UI.
var loader = new Windows.ApplicationModel.Resources.ResourceLoader();
this.UserNameTextBlock.Text = loader.GetString("MicrosoftAccount/Text");
// Show sign-in button.
SignInButton.Visibility = Visibility.Visible;
SignOutButton.Visibility = Visibility.Collapsed;
}
catch (LiveConnectException x)
{
// Handle exception.
}
}
示例7: SetNameField
private async Task SetNameField(Boolean login)
{
// await App.updateUserName(this.userName, login);
this.userName.Text = Connection.UserName;
Boolean userCanSignOut = true;
LiveAuthClient LCAuth = new LiveAuthClient();
LiveLoginResult LCLoginResult = await LCAuth.InitializeAsync();
if (LCLoginResult.Status == LiveConnectSessionStatus.Connected)
{
userCanSignOut = LCAuth.CanLogout;
}
if (this.userName.Text.Equals("You're not signed in."))
{
// Show sign-in button.
signInBtn.Visibility = Windows.UI.Xaml.Visibility.Visible;
signOutBtn.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
}
else
{
// Show sign-out button if they can sign out.
signOutBtn.Visibility = (userCanSignOut ? Windows.UI.Xaml.Visibility.Visible : Windows.UI.Xaml.Visibility.Collapsed);
signInBtn.Visibility = Windows.UI.Xaml.Visibility.Collapsed;
}
}
示例8: LoginAsync
public async Task<bool> LoginAsync(bool isSilent = true)
{
bool result = false;
LastError = null;
RestoreData = null;
IsInProgress = true;
try
{
var authClient = new LiveAuthClient();
LiveLoginResult res = isSilent ? await authClient.InitializeAsync(scopes) : await authClient.LoginAsync(scopes);
Session = res.Status == LiveConnectSessionStatus.Connected ? res.Session : null;
result = true;
}
catch (LiveAuthException ex)
{
LastError = ex.Message;
}
IsInProgress = false;
return result;
//CheckPendingBackgroundOperations();
}
示例9: login_Client
//인스턴스 생성용 method
private async void login_Client()
{
try
{
//Client 생성
authClient = new LiveAuthClient();
//초기화
result = await authClient.InitializeAsync();
//로그인
loginResult = await authClient.LoginAsync(scope);
//로그인 할 떄 cancel을 누르면 뒤로 돌아가기
}
catch (NullReferenceException ex)
{
//로그인 할 때 cancel을 누르면 nullreferenceException 발생
//뒤로가기
ex.Message.ToString();
messagePrint(false);
if (Frame.CanGoBack)
{
Frame.GoBack();
}
}
catch (Exception ex)
{
//기타 Exception을 위한 catch
ex.Message.ToString();
messagePrint(false);
if(Frame.CanGoBack)
{
Frame.GoBack();
}
}
}
示例10: TestLiveSDKLogin
/// <summary>
/// Tests logging into MobileService with Live SDK token. App needs to be assosciated with a WindowsStoreApp
/// </summary>
private async Task TestLiveSDKLogin()
{
try
{
LiveAuthClient liveAuthClient = new LiveAuthClient(GetClient().MobileAppUri.ToString());
LiveLoginResult result = await liveAuthClient.InitializeAsync(new string[] { "wl.basic", "wl.offline_access", "wl.signin" });
if (result.Status != LiveConnectSessionStatus.Connected)
{
result = await liveAuthClient.LoginAsync(new string[] { "wl.basic", "wl.offline_access", "wl.signin" });
}
if (result.Status == LiveConnectSessionStatus.Connected)
{
LiveConnectSession session = result.Session;
LiveConnectClient client = new LiveConnectClient(result.Session);
LiveOperationResult meResult = await client.GetAsync("me");
MobileServiceUser loginResult = await GetClient().LoginWithMicrosoftAccountAsync(result.Session.AuthenticationToken);
Log(string.Format("{0} is now logged into MobileService with userId - {1}", meResult.Result["first_name"], loginResult.UserId));
}
}
catch (Exception exception)
{
Log(string.Format("ExceptionType: {0} Message: {1} StackTrace: {2}",
exception.GetType().ToString(),
exception.Message,
exception.StackTrace));
Assert.Fail("Log in with Live SDK failed");
}
}
示例11: DoLogin
public async void DoLogin(string clientId)
{
var scopes = new List<string>();
scopes.Add("wl.calendars");
scopes.Add("http://outlook.office.com/Calendars.ReadWrite");
var sdk = new LiveAuthClient(clientId);
var result = await sdk.InitializeAsync(scopes);
var url = sdk.GetLoginUrl(scopes);
var token = sdk.Session.AuthenticationToken;
}
示例12: Activate
public async Task Activate()
{
var session = _cache.SkydriveSession;
if (session == null)
{
var authClient = new LiveAuthClient(ApiKeys.SkyDriveClientId);
var x = await authClient.InitializeAsync();
session = x.Session;
}
_liveClient = new LiveConnectClient(session);
}
示例13: GetSession
public async Task<LiveConnectSession> GetSession()
{
_client = new LiveAuthClient(_clientId, _tokenHandler);
var existingToken = await _tokenHandler.RetrieveRefreshTokenAsync();
if (existingToken != null)
{
var loginResult = await _client.InitializeAsync();
return loginResult.Session;
}
return await LoginAsync();
}
示例14: OnActivate
protected async override Task OnActivate()
{
if (authClient == null)
{
authClient = new LiveAuthClient(ApiKeys.SkyDriveClientId);
IEnumerable<string> scopes = ParseScopeString(Scopes);
try
{
Task<LiveLoginResult> result = authClient.InitializeAsync(scopes);
LiveLoginResult = await result;
}
catch (Exception exception)
{
//this.RaiseSessionChangedEvent(new LiveConnectSessionChangedEventArgs(exception));
}
}
}
示例15: authenticate2
// Normal Auth
private async Task<MobileServiceUser> authenticate2(bool singleSignOn)
{
LiveAuthClient liveIdClient = new LiveAuthClient("https://debtor.azure-mobile.net/");
var reqs = new[] { "wl.signin", "wl.basic", "wl.offline_access" };
LiveLoginResult init = await liveIdClient.InitializeAsync(reqs);
if (init.Status != LiveConnectSessionStatus.Connected)
{
try
{
await App.MobileService
.LoginAsync(MobileServiceAuthenticationProvider.MicrosoftAccount, singleSignOn);
}
catch (InvalidOperationException)
{
}
}
return App.MobileService.CurrentUser;
}