public static GetSyncUser ( string identity, string refreshToken, string authServerUrl, bool isAdmin ) : |
||
identity | string | |
refreshToken | string | |
authServerUrl | string | |
isAdmin | bool | |
Результат |
/// <summary> /// Logs the user in to the Realm Object Server. /// </summary> /// <param name="credentials">The credentials to use for authentication.</param> /// <param name="serverUri">The URI of the server that the user is authenticated against.</param> /// <returns>An awaitable Task, that, upon completion, contains the logged in user.</returns> public static async Task <User> LoginAsync(Credentials credentials, Uri serverUri) { Argument.NotNull(credentials, nameof(credentials)); Argument.NotNull(serverUri, nameof(serverUri)); Argument.Ensure(serverUri.Scheme.StartsWith("http"), "Unexpected protocol for login url. Expected http:// or https://.", nameof(serverUri)); SharedRealmHandleExtensions.DoInitialFileSystemConfiguration(); if (credentials.IdentityProvider == Credentials.Provider.AdminToken) { return(new User(SyncUserHandle.GetAdminTokenUser(serverUri.AbsoluteUri, credentials.Token))); } if (credentials.IdentityProvider == Credentials.Provider.CustomRefreshToken) { var userId = (string)credentials.UserInfo[Credentials.Keys.Identity]; var isAdmin = (bool)credentials.UserInfo[Credentials.Keys.IsAdmin]; return(new User(SyncUserHandle.GetSyncUser(userId, serverUri.AbsoluteUri, credentials.Token, isAdmin))); } var result = await AuthenticationHelper.LoginAsync(credentials, serverUri); var handle = SyncUserHandle.GetSyncUser(result.UserId, serverUri.AbsoluteUri, result.RefreshToken, result.IsAdmin); return(new User(handle)); }
public static async Task <User> LoginAsync(Credentials credentials, Uri serverUrl, LoginMode loginMode = LoginMode.UseExistingAccount) { if (credentials.IdentityProvider == Credentials.Providers.AccessToken) { var identity = (string)credentials.UserInfo[Credentials.Keys.Identity]; var isAdmin = (bool)credentials.UserInfo[Credentials.Keys.IsAdmin]; return(new User(SyncUserHandle.GetSyncUser(identity, credentials.Token, serverUrl?.AbsoluteUri, isAdmin))); } var result = await MakeAuthRequestAsync(serverUrl, credentials.ToJson(), TimeSpan.FromSeconds(30)).ConfigureAwait(continueOnCapturedContext: false); var refresh_token = result["refresh_token"]; return(new User(SyncUserHandle.GetSyncUser(refresh_token["token_data"]["identity"], refresh_token["token"], serverUrl.AbsoluteUri, false))); }
/// <summary> /// Logs the user in to the Realm Object Server. /// </summary> /// <param name="credentials">The credentials to use for authentication.</param> /// <param name="serverUrl">The URI of the server that the user is authenticated against.</param> /// <returns>An awaitable Task, that, upon completion, contains the logged in user.</returns> public static async Task <User> LoginAsync(Credentials credentials, Uri serverUrl) { SharedRealmHandleExtensions.DoInitialFileSystemConfiguration(); if (credentials.IdentityProvider == Credentials.Providers.AccessToken) { var identity = (string)credentials.UserInfo[Credentials.Keys.Identity]; var isAdmin = (bool)credentials.UserInfo[Credentials.Keys.IsAdmin]; return(new User(SyncUserHandle.GetSyncUser(identity, credentials.Token, serverUrl?.AbsoluteUri, isAdmin))); } var result = await AuthenticationHelper.Login(credentials, serverUrl); return(new User(SyncUserHandle.GetSyncUser(result.Item1, result.Item2, serverUrl.AbsoluteUri, isAdmin: false))); }