use std::collections::{BTreeMap, BTreeSet};
use std::fmt;
use std::sync::{Arc, RwLock};
use async_stream::stream;
use async_trait::async_trait;
use futures::Stream;
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use plexus_auth_core::grants::{
Ceiling, Gate, Grant, GrantSet, GrantsGeneration, GrantsMove, Liveness, Membership, Memberships, Reach, Refusal, Resolve, Roles, ScopeRef, ADMIN,
};
use plexus_auth_core::identity::Principal;
use plexus_auth_core::RoleName;
use super::auth::AuthContext;
use super::auth_params as param;
use super::schema::{MethodRole, PluginSchema};
pub const SIGNED_IN_GRANTS: [&str; 3] = ["auth.whoami", "auth.logout", "auth.requires"];
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum ProviderKind {
Browser,
Password,
Key,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct Provider {
pub name: String,
pub kind: ProviderKind,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub label: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum LoginFlow {
Browser { redirect: String },
Code { code: String, state: String },
Password { username: String, password: String },
Session {
#[serde(default)]
ttl_secs: Option<u64>,
#[serde(default)]
ceiling: Option<Vec<String>>,
},
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct Session {
pub token: String,
pub principal: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub agent: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
pub expires_at: i64,
#[serde(default)]
pub ceiling: Vec<String>,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct Waiting {
pub principal: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub provider: Option<String>,
pub since: i64,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum LoginAnswer {
LoginUrl { url: String, state: String },
Session(Session),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum SignupAnswer {
Waiting(Waiting),
LoginUrl { url: String, state: String },
Session(Session),
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct AuthFailure(pub String);
impl AuthFailure {
pub fn new(message: impl Into<String>) -> Self {
Self(message.into())
}
}
impl fmt::Display for AuthFailure {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
impl std::error::Error for AuthFailure {}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct StoreError(pub String);
impl StoreError {
pub fn new(message: impl Into<String>) -> Self {
Self(message.into())
}
}
impl fmt::Display for StoreError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
impl std::error::Error for StoreError {}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
pub struct MembershipEntry {
pub role: String,
pub scope: String,
}
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum AuthEvent {
Provider {
name: String,
kind: ProviderKind,
#[serde(default, skip_serializing_if = "Option::is_none")]
label: Option<String>,
},
LoginUrl { url: String, state: String },
Session {
token: String,
principal: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
agent: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
name: Option<String>,
expires_at: i64,
#[serde(default)]
ceiling: Vec<String>,
},
Waiting {
principal: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
name: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
provider: Option<String>,
since: i64,
},
Whoami {
principal: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
name: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
agent: Option<String>,
memberships: Vec<MembershipEntry>,
ceiling: Vec<String>,
},
LoggedOut { principal: String },
Requires {
method: String,
grant: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
target: Option<String>,
roles: Vec<String>,
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
public: bool,
},
Role {
role: String,
grants: Vec<String>,
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
all: bool,
},
Granted { principal: String, role: String, scope: String },
Revoked { principal: String, scope: String, roles: Vec<String> },
Error {
message: String,
#[serde(default, skip_serializing_if = "Option::is_none")]
error_kind: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
grant: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
scope: Option<String>,
#[serde(default, skip_serializing_if = "Option::is_none")]
roles: Option<Vec<String>>,
#[serde(default, skip_serializing_if = "Option::is_none")]
held_on: Option<Vec<String>>,
},
}
impl AuthEvent {
fn error(message: impl Into<String>) -> Self {
Self::Error { message: message.into(), error_kind: None, grant: None, scope: None, roles: None, held_on: None }
}
}
impl plexus_client::FromClientError for AuthEvent {
fn from_client_error(error: plexus_client::ClientError) -> Self {
Self::error(error.to_string())
}
}
impl From<Session> for AuthEvent {
fn from(s: Session) -> Self {
Self::Session {
token: s.token,
principal: s.principal,
agent: s.agent,
name: s.name,
expires_at: s.expires_at,
ceiling: s.ceiling,
}
}
}
impl From<Waiting> for AuthEvent {
fn from(w: Waiting) -> Self {
Self::Waiting { principal: w.principal, name: w.name, provider: w.provider, since: w.since }
}
}
#[async_trait]
pub trait AuthBackend: Send + Sync + 'static {
fn providers(&self) -> Vec<Provider>;
async fn login(&self, caller: Option<&AuthContext>, flow: LoginFlow) -> Result<LoginAnswer, AuthFailure>;
async fn signup(&self, caller: Option<&AuthContext>, via: Option<String>) -> Result<SignupAnswer, AuthFailure>;
async fn ask_access(&self, caller: &AuthContext, via: Option<String>) -> Result<Waiting, AuthFailure>;
fn waiting(&self) -> Vec<Waiting>;
async fn logout(&self, caller: &AuthContext) -> Result<(), AuthFailure>;
fn alive(&self, caller: &AuthContext) -> Result<(), String>;
}
struct BackendLiveness(Arc<dyn AuthBackend>);
impl Liveness for BackendLiveness {
fn alive(&self, caller: &AuthContext) -> Result<(), String> {
self.0.alive(caller)
}
}
#[async_trait]
pub trait RoleStore: Roles + 'static {
async fn set(&self, role: &RoleName, grants: GrantSet) -> Result<(), StoreError>;
}
#[async_trait]
pub trait MembershipStore: Memberships + 'static {
async fn grant(&self, membership: Membership) -> Result<(), StoreError>;
async fn revoke(
&self,
principal: &Principal,
role: Option<&RoleName>,
scope: &ScopeRef,
) -> Result<Vec<RoleName>, StoreError>;
}
#[derive(Clone)]
pub struct AuthSetup {
pub backend: Arc<dyn AuthBackend>,
pub roles: Arc<dyn RoleStore>,
pub memberships: Arc<dyn MembershipStore>,
pub resolve: Arc<dyn Resolve>,
pub generation: Option<GrantsGeneration>,
}
impl AuthSetup {
pub fn new(
backend: Arc<dyn AuthBackend>,
roles: Arc<dyn RoleStore>,
memberships: Arc<dyn MembershipStore>,
resolve: Arc<dyn Resolve>,
) -> Self {
Self { backend, roles, memberships, resolve, generation: None }
}
pub fn with_generation(mut self, generation: GrantsGeneration) -> Self {
self.generation = Some(generation);
self
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Requirement {
pub grant: String,
pub target: Option<String>,
pub public: bool,
}
#[derive(Clone, Default)]
pub struct Catalog(Arc<RwLock<BTreeMap<String, Requirement>>>);
impl Catalog {
pub(crate) fn add(&self, schema: &PluginSchema) {
let mut map = self.0.write().unwrap_or_else(|p| p.into_inner());
for m in &schema.methods {
if m.is_auto_schema() || !matches!(m.role, MethodRole::Rpc) {
continue;
}
let grant = m.grant_or(&schema.namespace);
map.insert(grant.clone(), Requirement { grant, target: m.target.clone(), public: m.public });
}
}
pub fn get(&self, method: &str) -> Option<Requirement> {
self.0.read().unwrap_or_else(|p| p.into_inner()).get(method).cloned()
}
pub fn knows(&self, grant: &str) -> bool {
self.0.read().unwrap_or_else(|p| p.into_inner()).contains_key(grant)
}
}
#[derive(Clone)]
pub struct AuthActivation {
inner: Arc<AuthInner>,
}
struct AuthInner {
backend: Arc<dyn AuthBackend>,
roles: Arc<dyn RoleStore>,
memberships: Arc<dyn MembershipStore>,
gate: Gate,
catalog: Catalog,
}
struct WithEverywhere(Arc<dyn Resolve>);
impl Resolve for WithEverywhere {
fn chain(&self, target: &str) -> Option<Vec<ScopeRef>> {
if target.trim() == "*" {
return Some(vec![ScopeRef::Everywhere]);
}
self.0.chain(target)
}
}
impl AuthActivation {
pub(crate) fn mount(setup: AuthSetup, catalog: Catalog) -> (Self, Gate) {
let memberships: Arc<dyn Memberships> = setup.memberships.clone();
let roles: Arc<dyn Roles> = setup.roles.clone();
let mut gate = Gate::new(memberships, roles, Arc::new(WithEverywhere(setup.resolve)))
.with_liveness(Arc::new(BackendLiveness(setup.backend.clone())));
if let Some(generation) = setup.generation {
gate = gate.with_generation(generation);
}
let auth = Self {
inner: Arc::new(AuthInner {
backend: setup.backend,
roles: setup.roles,
memberships: setup.memberships,
gate: gate.clone(),
catalog,
}),
};
(auth, gate)
}
}
fn principal_of(ctx: &AuthContext) -> Option<Principal> {
ctx.principal()
}
fn meta(ctx: &AuthContext, key: &str) -> Option<String> {
ctx.get_metadata_string(key).filter(|s| !s.is_empty())
}
fn needs_everywhere(gate: &Gate, grant: &str, reach: &Reach) -> AuthEvent {
let g = Grant::new(grant);
AuthEvent::Error {
message: format!("needs {grant} on *"),
error_kind: Some("forbidden".into()),
grant: Some(grant.into()),
scope: Some("*".into()),
roles: Some(gate.roles_listing(&g).iter().map(|r| r.as_str().to_string()).collect()),
held_on: Some(reach.held_on().iter().map(|s| s.as_str().to_string()).collect()),
}
}
fn holds_where_written(gate: &Gate, caller: &AuthContext, reach: &Reach, grant: &str, scopes: &[&str]) -> Result<(), Box<AuthEvent>> {
let g = Grant::new(grant);
if reach.grant() != Some(&g) {
return Err(Box::new(needs_on(gate, grant, "*", reach.held_on())));
}
for scope in scopes {
match gate.check(Some(caller), &g, Some(scope)) {
Ok(_) => {}
Err(Refusal::MissingGrant { scope, held_on, .. }) => return Err(Box::new(needs_on(gate, grant, scope.as_str(), &held_on))),
Err(Refusal::Ended { reason }) => return Err(Box::new(AuthEvent::error(reason))),
Err(Refusal::Unauthenticated) => return Err(Box::new(AuthEvent::error("sign in first"))),
}
}
Ok(())
}
fn needs_on(gate: &Gate, grant: &str, scope: &str, held_on: &[ScopeRef]) -> AuthEvent {
AuthEvent::Error {
message: format!("needs {grant} on {scope}"),
error_kind: Some("forbidden".into()),
grant: Some(grant.into()),
scope: Some(scope.into()),
roles: Some(gate.roles_listing(&Grant::new(grant)).iter().map(|r| r.as_str().to_string()).collect()),
held_on: Some(held_on.iter().map(|s| s.as_str().to_string()).collect()),
}
}
fn role_event(role: &RoleName, grants: Option<GrantSet>) -> AuthEvent {
match grants {
Some(GrantSet::All) => AuthEvent::Role { role: role.as_str().into(), grants: Vec::new(), all: true },
Some(GrantSet::Listed(set)) => AuthEvent::Role {
role: role.as_str().into(),
grants: set.iter().map(|g| g.as_str().to_string()).collect(),
all: false,
},
None => AuthEvent::Role { role: role.as_str().into(), grants: Vec::new(), all: false },
}
}
#[plexus_macros::activation(
version = "1.0.0",
description = "Sign in, who am I, what does this need",
roles(member = ["whoami", "logout", "requires"]),
// MACRO-12: every parameter is a type (`super::auth_params`); a bare
// string parameter does not compile here.
typed_params,
)]
impl AuthActivation {
#[plexus_macros::method(public, group = "sign in", description = "The ways in this server offers")]
async fn providers(&self) -> impl Stream<Item = AuthEvent> + Send + 'static {
let providers = self.inner.backend.providers();
stream! {
for p in providers {
yield AuthEvent::Provider { name: p.name, kind: p.kind, label: p.label };
}
}
}
#[plexus_macros::method(
public,
group = "sign in",
description = "Sign in — a person through the browser, an agent with its key",
params(flow = "browser {redirect} | code {code, state} | password {username, password} | session {ttl_secs?, ceiling?}")
)]
async fn login(&self, auth: Option<&AuthContext>, flow: LoginFlow) -> impl Stream<Item = AuthEvent> + Send + 'static {
let inner = self.inner.clone();
let caller = auth.cloned();
stream! {
if let LoginFlow::Session { ceiling: Some(entries), .. } = &flow {
if let Err(e) = Ceiling::parse(entries) {
yield AuthEvent::error(format!("ceiling: {e}"));
return;
}
}
if matches!(flow, LoginFlow::Session { .. }) && caller.as_ref().and_then(principal_of).is_none() {
yield AuthEvent::error("a session needs a connection that is someone: a key proof at the upgrade, or a session");
return;
}
match inner.backend.login(caller.as_ref(), flow).await {
Ok(LoginAnswer::LoginUrl { url, state }) => yield AuthEvent::LoginUrl { url, state },
Ok(LoginAnswer::Session(s)) => yield s.into(),
Err(e) => yield AuthEvent::error(e.0),
}
}
}
#[plexus_macros::method(
public,
group = "sign in",
description = "Create an account, or ask for access",
params(via = "The provider to sign up through, where the server offers several")
)]
async fn signup(&self, auth: Option<&AuthContext>, via: Option<param::ProviderName>) -> impl Stream<Item = AuthEvent> + Send + 'static {
let inner = self.inner.clone();
let caller = auth.cloned();
let via = via.map(param::ProviderName::into_string);
stream! {
let holds_none = caller
.as_ref()
.and_then(principal_of)
.map(|p| inner.memberships.own_held(&p).is_empty());
let answer = match (holds_none, caller.as_ref()) {
(Some(true), Some(ctx)) => inner.backend.ask_access(ctx, via).await.map(SignupAnswer::Waiting),
_ => inner.backend.signup(caller.as_ref(), via).await,
};
match answer {
Ok(SignupAnswer::Waiting(w)) => yield w.into(),
Ok(SignupAnswer::LoginUrl { url, state }) => yield AuthEvent::LoginUrl { url, state },
Ok(SignupAnswer::Session(s)) => yield s.into(),
Err(e) => yield AuthEvent::error(e.0),
}
}
}
#[plexus_macros::method(group = "you", description = "Who you are: principal, roles held where, ceiling")]
async fn whoami(&self, auth: &AuthContext) -> impl Stream<Item = AuthEvent> + Send + 'static {
let inner = self.inner.clone();
let ctx = auth.clone();
stream! {
let Some(p) = principal_of(&ctx) else {
yield AuthEvent::error("sign in first");
return;
};
let memberships = inner
.memberships
.held(&p)
.into_iter()
.map(|m| MembershipEntry { role: m.role.as_str().into(), scope: m.scope.as_str().into() })
.collect();
let ceiling = Ceiling::layers_of(&ctx)
.map(|layers| layers.iter().flat_map(|l| l.text()).collect())
.unwrap_or_default();
yield AuthEvent::Whoami {
principal: p.to_string(),
name: meta(&ctx, "name"),
agent: meta(&ctx, "agent"),
memberships,
ceiling,
};
}
}
#[plexus_macros::method(group = "you", description = "Sign out: end this session")]
async fn logout(&self, auth: &AuthContext) -> impl Stream<Item = AuthEvent> + Send + 'static {
let inner = self.inner.clone();
let ctx = auth.clone();
stream! {
let principal = principal_of(&ctx).map(|p| p.to_string()).unwrap_or_default();
match inner.backend.logout(&ctx).await {
Ok(()) => {
inner.gate.moved(GrantsMove::SignOut);
yield AuthEvent::LoggedOut { principal }
}
Err(e) => yield AuthEvent::error(e.0),
}
}
}
#[plexus_macros::method(
group = "you",
description = "What a method needs: its grant, target, and the roles that list it",
params(method = "The method, as <activation>.<method>: tickets.set_status"),
example(note = "what changing a ticket's status needs", params = r#"{"method": "tickets.set_status"}"#)
)]
async fn requires(&self, auth: &AuthContext, method: param::MethodPath) -> impl Stream<Item = AuthEvent> + Send + 'static {
let _ = auth;
let inner = self.inner.clone();
stream! {
match inner.catalog.get(method.as_str()) {
None => yield AuthEvent::error(format!("no method {method} here")),
Some(req) => {
let roles = inner.gate.roles_listing(&Grant::new(req.grant.clone()));
yield AuthEvent::Requires {
method: method.into_string(),
grant: req.grant,
target: req.target,
roles: roles.iter().map(|r| r.as_str().to_string()).collect(),
public: req.public,
};
}
}
}
}
#[plexus_macros::method(group = "admin", description = "Every role and the grants it lists")]
async fn roles(&self, auth: &AuthContext) -> impl Stream<Item = AuthEvent> + Send + 'static {
let _ = auth;
let inner = self.inner.clone();
stream! {
let admin = RoleName::new(ADMIN);
yield role_event(&admin, Some(GrantSet::All));
let names: BTreeSet<RoleName> = inner.roles.names().into_iter().filter(|r| r.as_str() != ADMIN).collect();
for r in names {
let grants = inner.roles.grants(&r);
yield role_event(&r, grants);
}
}
}
#[plexus_macros::method(
group = "admin",
description = "Set a role's grants (admin on *)",
params(role = "The role (not admin)", grants = "Grants (tickets.get) or roles to include")
)]
async fn role_set(&self, auth: &AuthContext, reach: Reach, role: param::RoleName, grants: Vec<param::GrantName>) -> impl Stream<Item = AuthEvent> + Send + 'static {
let _ = auth;
let inner = self.inner.clone();
stream! {
if !reach.is_everywhere() || reach.grant() != Some(&Grant::new("auth.role_set")) {
yield needs_everywhere(&inner.gate, "auth.role_set", &reach);
return;
}
if role.as_str() == ADMIN {
yield AuthEvent::error("admin holds every grant; it is not edited");
return;
}
let mut set: BTreeSet<Grant> = BTreeSet::new();
for entry in grants.iter() {
let entry = entry.as_str();
if entry.contains('.') {
if !inner.catalog.knows(entry) {
yield AuthEvent::error(format!("no method {entry} here"));
return;
}
set.insert(Grant::new(entry));
} else {
match inner.roles.grants(&RoleName::new(entry)) {
Some(GrantSet::Listed(included)) => set.extend(included),
Some(GrantSet::All) => {
yield AuthEvent::error(format!("{entry} holds every grant; a role cannot include it"));
return;
}
None => {
yield AuthEvent::error(format!("no role {entry} to include"));
return;
}
}
}
}
let name = role.role();
if let Err(e) = inner.roles.set(&name, GrantSet::Listed(set)).await {
yield AuthEvent::error(e.0);
return;
}
inner.gate.moved(GrantsMove::RoleEdit);
let now = inner.roles.grants(&name);
yield role_event(&name, now);
}
}
#[plexus_macros::method(
target = "scope",
group = "admin",
description = "Give a principal a role on a scope",
params(principal = "key:…, oidc:…/…, idp:…", role = "The role", scope = "Where: a scope name, or *"),
example(note = "make a person an editor on MENGER", params = r#"{"principal": "oidc:workos/user_01M4", "role": "editor", "scope": "MENGER"}"#),
example(note = "make an agent's key an admin everywhere", params = r#"{"principal": "key:ac79e0d1f2a3b4c5d6e7f8091a2b3c4d5e6f708192a3b4c5d6e7f8091a2b3c4d", "role": "admin", "scope": "*"}"#)
)]
async fn grant(&self, auth: &AuthContext, reach: Reach, principal: param::Principal, role: param::RoleName, scope: param::ScopeName) -> impl Stream<Item = AuthEvent> + Send + 'static {
let inner = self.inner.clone();
let caller = auth.clone();
stream! {
let who: Principal = principal.principal();
let role_name = role.role();
if role_name.as_str() != ADMIN && inner.roles.grants(&role_name).is_none() {
yield AuthEvent::error(format!("no role {role} here"));
return;
}
let scope_ref = scope.scope();
if let Err(refused) = holds_where_written(&inner.gate, &caller, &reach, "auth.grant", &[scope.as_str(), scope_ref.as_str()]) {
yield *refused;
return;
}
let m = Membership { principal: who.clone(), role: role_name.clone(), scope: scope_ref.clone() };
match inner.memberships.grant(m).await {
Ok(()) => {
inner.gate.moved(GrantsMove::Grant);
yield AuthEvent::Granted {
principal: who.to_string(),
role: role_name.as_str().into(),
scope: scope_ref.as_str().into(),
}
}
Err(e) => yield AuthEvent::error(e.0),
}
}
}
#[plexus_macros::method(
target = "scope",
group = "admin",
description = "Take a principal's role on a scope away",
params(principal = "key:…, oidc:…/…, idp:…", role = "The role; absent: every role there", scope = "Where: a scope name, or *")
)]
async fn revoke(&self, auth: &AuthContext, reach: Reach, principal: param::Principal, role: Option<param::RoleName>, scope: param::ScopeName) -> impl Stream<Item = AuthEvent> + Send + 'static {
let inner = self.inner.clone();
let caller = auth.clone();
stream! {
let who: Principal = principal.principal();
let scope_ref = scope.scope();
if let Err(refused) = holds_where_written(&inner.gate, &caller, &reach, "auth.revoke", &[scope.as_str(), scope_ref.as_str()]) {
yield *refused;
return;
}
let role_name = role.as_ref().map(param::RoleName::role);
match inner.memberships.revoke(&who, role_name.as_ref(), &scope_ref).await {
Ok(removed) => {
if !removed.is_empty() {
inner.gate.moved(GrantsMove::Revoke);
}
yield AuthEvent::Revoked {
principal: who.to_string(),
scope: scope_ref.as_str().into(),
roles: removed.iter().map(|r| r.as_str().to_string()).collect(),
}
}
Err(e) => yield AuthEvent::error(e.0),
}
}
}
#[plexus_macros::method(group = "admin", description = "Who asked for access and holds nothing yet (admin on *)")]
async fn waiting(&self, auth: &AuthContext, reach: Reach) -> impl Stream<Item = AuthEvent> + Send + 'static {
let _ = auth;
let inner = self.inner.clone();
stream! {
if !reach.is_everywhere() || reach.grant() != Some(&Grant::new("auth.waiting")) {
yield needs_everywhere(&inner.gate, "auth.waiting", &reach);
return;
}
for w in inner.backend.waiting() {
let still = w
.principal
.parse::<Principal>()
.map(|p| inner.memberships.own_held(&p).is_empty())
.unwrap_or(true);
if still {
yield w.into();
}
}
}
}
}