internal bool TryAuthenticate(string apiKeyHash, out Forbidden error) { error = null; AccessRights = Authenticator.GetAccessRights(apiKeyHash); if (!RESTarConfig.RequireApiKey) { AccessRights = AccessRights.Root; } if (AccessRights == null) { error = new NotAuthorized(); return(false); } return(true); }
/// <inheritdoc /> protected override void BuildRenderTree(RenderTreeBuilder builder) { if (currentAuthenticationState == null) { builder.AddContent(0, Authorizing); } else if (isAuthorized) { var authorizedContent = Authorized ?? ChildContent; builder.AddContent(1, authorizedContent?.Invoke(currentAuthenticationState)); } else { builder.AddContent(2, NotAuthorized?.Invoke(currentAuthenticationState)); } }
/// <inheritdoc /> protected override void BuildRenderTree(RenderTreeBuilder builder) { // We're using the same sequence number for each of the content items here // so that we can update existing instances if they are the same shape if (currentAuthenticationState == null) { builder.AddContent(0, Authorizing); } else if (isAuthorized) { var authorized = Authorized ?? ChildContent; builder.AddContent(0, authorized?.Invoke(currentAuthenticationState)); } else { builder.AddContent(0, NotAuthorized?.Invoke(currentAuthenticationState)); } }
/// <summary> /// Returns true if and only if this client is considered authenticated. This is a necessary precondition for /// being included in a context. If false, a NotAuthorized result object is returned in the out parameter, that /// can be returned to the client. /// </summary> /// <param name="uri">The URI of the request</param> /// <param name="headers">The headers of the request</param> /// <param name="error">The error result, if not authenticated</param> /// <returns></returns> public bool TryAuthenticate(ref string uri, Headers headers, out Forbidden error) { error = null; AccessRights = Authenticator.GetAccessRights(ref uri, headers); if (!RESTarConfig.RequireApiKey) { AccessRights = AccessRights.Root; } if (AccessRights == null) { error = new NotAuthorized(); if (headers.Metadata == "full") { error.Headers.Metadata = error.Metadata; } return(false); } return(true); }
internal static bool TryCreate(string apiKey, out Context context, out Error error) { var _context = new WebhookContext(apiKey); var accessRights = Authenticator.GetAccessRights(apiKey); if (!RESTarConfig.RequireApiKey) { accessRights = AccessRights.Root; } if (accessRights == null) { context = null; error = new NotAuthorized(); return(false); } context = _context; context.Client.AccessRights = accessRights; error = null; return(true); }