private static unsafe void HandleUserCallback(IntPtr tcs_ptr, IntPtr user_ptr, AppError error) { var tcsHandle = GCHandle.FromIntPtr(tcs_ptr); try { var tcs = (TaskCompletionSource <SyncUserHandle>)tcsHandle.Target; if (error.is_null) { var userHandle = new SyncUserHandle(user_ptr); tcs.TrySetResult(userHandle); } else { tcs.TrySetException(new AppException(error)); } } finally { tcsHandle.Free(); } }
public static extern bool get_is_admin(SyncUserHandle user);
public static extern IntPtr get_server_url(SyncUserHandle user, IntPtr buffer, IntPtr buffer_length, out NativeException ex);
public static extern IntPtr get_refresh_token(SyncUserHandle user, IntPtr buffer, IntPtr buffer_length, out NativeException ex);
public static extern IntPtr switch_user(AppHandle app, SyncUserHandle user, out NativeException ex);
public void SwitchUser(SyncUserHandle user) { NativeMethods.switch_user(this, user, out var ex); ex.ThrowIfNecessary(); }
public static extern IntPtr get_identities(SyncUserHandle handle, IntPtr buffer, IntPtr bufsize, out NativeException ex);
public static extern void set_is_admin(SyncUserHandle user, [MarshalAs(UnmanagedType.I1)] bool value, out NativeException ex);
public static extern void log_out(SyncUserHandle user, out NativeException ex);
public static extern UserState get_state(SyncUserHandle user, out NativeException ex);
private static SyncUserHandle GetHandle(IntPtr ptr) { if (ptr == IntPtr.Zero) { return null; } var handle = new SyncUserHandle(); handle.SetHandle(ptr); return handle; }
public static extern IntPtr get_path_for_realm(SyncUserHandle user, [MarshalAs(UnmanagedType.LPWStr)] string url, IntPtr url_len, IntPtr buffer, IntPtr bufsize, out NativeException ex);
private static unsafe void RefreshAccessTokenCallback(IntPtr userHandlePtr, IntPtr sessionHandlePtr, sbyte* urlBuffer, IntPtr urlLength) { var userHandle = new SyncUserHandle(); userHandle.SetHandle(userHandlePtr); var user = new User(userHandle); var session = Session.SessionForPointer(sessionHandlePtr); var realmUri = new Uri(new string(urlBuffer, 0, (int)urlLength, System.Text.Encoding.UTF8)); user.RefreshAccessToken(realmUri.AbsolutePath) .ContinueWith(t => { if (t.IsFaulted) { session.RaiseError(t.Exception.GetBaseException()); } else { session.Handle.RefreshAccessToken(t.Result.Item1, t.Result.Item2); } }).ContinueWith(t => { userHandle.Dispose(); }); }
public static extern IntPtr get_session(SyncUserHandle user, [MarshalAs(UnmanagedType.LPWStr)] string path, IntPtr path_len, out NativeException ex);
internal User(SyncUserHandle handle) { Handle = handle; _permissionRealm = new Lazy <Realm>(() => GetSpecialPurposeRealm("__permission", typeof(PathPermission))); _managementRealm = new Lazy <Realm>(() => GetSpecialPurposeRealm("__management", typeof(PermissionChange), typeof(PermissionOffer), typeof(PermissionOfferResponse))); }
internal User(SyncUserHandle handle) { Handle = handle; }
public static extern void link_credentials(SyncUserHandle handle, AppHandle app, Native.Credentials credentials, IntPtr tcs_ptr, out NativeException ex);
public static extern void create_api_key(SyncUserHandle handle, AppHandle app, [MarshalAs(UnmanagedType.LPWStr)] string name, IntPtr name_len, IntPtr tcs_ptr, out NativeException ex);
public static extern void push_deregister(SyncUserHandle handle, AppHandle app, [MarshalAs(UnmanagedType.LPWStr)] string service, IntPtr service_len, IntPtr tcs_ptr, out NativeException ex);
public static extern void fetch_api_keys(SyncUserHandle handle, AppHandle app, IntPtr tcs_ptr, out NativeException ex);
public static extern IntPtr get_path_for_realm(AppHandle app, SyncUserHandle user, [MarshalAs(UnmanagedType.LPWStr)] string partition, IntPtr partition_len, IntPtr buffer, IntPtr bufsize, out NativeException ex);
public static extern void enable_api_key(SyncUserHandle handle, AppHandle app, PrimitiveValue id, IntPtr tcs_ptr, out NativeException ex);
public static extern void remove_user(AppHandle app, SyncUserHandle user, IntPtr tcs_ptr, out NativeException ex);
public static extern Credentials.AuthProvider get_auth_provider(SyncUserHandle user, out NativeException ex);
public static extern IntPtr set_refresh_token(SyncUserHandle user, [MarshalAs(UnmanagedType.LPWStr)] string refresh_token, IntPtr refresh_token_len, out NativeException ex);
public static extern IntPtr get_profile_data(SyncUserHandle user, UserProfileField field, IntPtr buffer, IntPtr buffer_length, [MarshalAs(UnmanagedType.U1)] out bool isNull, out NativeException ex);
public static extern IntPtr get_custom_data(SyncUserHandle user, IntPtr buffer, IntPtr buffer_length, [MarshalAs(UnmanagedType.U1)] out bool isNull, out NativeException ex);
public static extern IntPtr get_app(SyncUserHandle user, out NativeException ex);
public static extern void refresh_custom_data(SyncUserHandle user, IntPtr tcs_ptr, out NativeException ex);
internal static User Create(IntPtr userPtr) { var userHandle = new SyncUserHandle(userPtr); return(new User(userHandle)); }
public static extern void call_function(SyncUserHandle handle, AppHandle app, [MarshalAs(UnmanagedType.LPWStr)] string function_name, IntPtr function_name_len, [MarshalAs(UnmanagedType.LPWStr)] string args, IntPtr args_len, IntPtr tcs_ptr, out NativeException ex);