You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Update webapp to call OPA to see if we can call the endpoint #332
publicclassOpaAuthorizationHandler:AuthorizationHandler<ProjectPermissionRequirement>{privatereadonlyHttpClient_opaClient;privatereadonlyIMongoCollection<Project>_projectsCollection;publicOpaAuthorizationHandler(HttpClientopaClient,IMongoDatabasedatabase){_opaClient=opaClient;_projectsCollection=database.GetCollection<Project>("Projects");}protectedoverrideasyncTaskHandleRequirementAsync(AuthorizationHandlerContextcontext,ProjectPermissionRequirementrequirement){// 1. Get Project ID from HttpContext Route ValuesvarhttpContext=context.ResourceasHttpContext;varprojectId=httpContext.Request.RouteValues["projectId"]?.ToString();varuserId=context.User.GetInternalUserId();// From our claims transform!// 2. Fetch the user's role for this project from MongoDBvarproject=await_projectsCollection.Find(p =>p.Id==projectId).FirstOrDefaultAsync();varuserRole=project?.Members.FirstOrDefault(m =>m.UserId==userId)?.Role??"none";// 3. Ask OPA for permissionvarrequestBody=new{input=new{project_role=userRole,action=requirement.Permission,is_system_admin=context.User.HasClaim("Role","SystemAdmin")}};// Call OPA evaluate endpoint (e.g., http://localhost:8181/v1/data/app/rbac/allow)varresponse=await_opaClient.PostAsJsonAsync("/v1/data/app/rbac/allow",requestBody);varopaResult=awaitresponse.Content.ReadFromJsonAsync<OpaResponse>();// 4. Grant or Deny based on OPA's answerif(opaResult?.Result==true){context.Succeed(requirement);}}}
Activity