using Inversion; namespace Spry.Authentication { /** * UserIdentityProvider implements the IdentityProvider interface from the * Authorisation system, bridging Authentication.User to Authorisation.Identity. * * This allows the Authorisation system to retrieve Identity objects using * the UserService for storage operations. * * Usage: * Register this as the IdentityProvider implementation in your IoC container: * container.register(); * * Or use directly: * var provider = new UserIdentityProvider(); * var identity = yield provider.get_identity_by_id("user-123"); */ public class UserIdentityProvider : GLib.Object, Authorisation.IdentityProvider { private UserService _user_service = inject(); /** * Creates a new UserIdentityProvider. * Dependencies are injected via inject<>() pattern. */ public UserIdentityProvider() { // Dependencies injected via field initializers } /** * Retrieves an Identity by its unique ID. * * This method looks up a User by ID and returns it as an Identity. * Since User implements Identity, no conversion is needed. * * @param id The user's unique identifier * @return The User as Identity, or null if not found * @throws Error on retrieval failure */ public async Authorisation.Identity? get_identity_by_id(string id) throws Error { var user = yield _user_service.get_user_async(id); return user; // User implements Identity } /** * Retrieves an Identity by its username. * * This method looks up a User by username and returns it as an Identity. * Since User implements Identity, no conversion is needed. * * @param username The username to look up * @return The User as Identity, or null if not found * @throws Error on retrieval failure */ public async Authorisation.Identity? get_identity_by_username(string username) throws Error { var user = yield _user_service.get_user_by_username_async(username); return user; // User implements Identity } } }