MCPcopy Create free account
hub / github.com/Commit-Boost/commit-boost-client / jwt_auth

Function jwt_auth

crates/signer/src/service.rs:138–166  ·  view source on GitHub ↗

Authentication middleware layer

(
    State(state): State<SigningState>,
    TypedHeader(auth): TypedHeader<Authorization<Bearer>>,
    addr: ConnectInfo<SocketAddr>,
    mut req: Request,
    next: Next,
)

Source from the content-addressed store, hash-verified

136
137/// Authentication middleware layer
138async fn jwt_auth(
139 State(state): State<SigningState>,
140 TypedHeader(auth): TypedHeader<Authorization<Bearer>>,
141 addr: ConnectInfo<SocketAddr>,
142 mut req: Request,
143 next: Next,
144) -> Result<Response, SignerModuleError> {
145 // Check if the request needs to be rate limited
146 let client_ip = addr.ip();
147 check_jwt_rate_limit(&state, &client_ip)?;
148
149 // Process JWT authorization
150 match check_jwt_auth(&auth, &state) {
151 Ok(module_id) => {
152 req.extensions_mut().insert(module_id);
153 Ok(next.run(req).await)
154 }
155 Err(SignerModuleError::Unauthorized) => {
156 let mut failures = state.jwt_auth_failures.write();
157 let failure_info = failures
158 .entry(client_ip)
159 .or_insert(JwtAuthFailureInfo { failure_count: 0, last_failure: Instant::now() });
160 failure_info.failure_count += 1;
161 failure_info.last_failure = Instant::now();
162 Err(SignerModuleError::Unauthorized)
163 }
164 Err(err) => Err(err),
165 }
166}
167
168/// Checks if the incoming request needs to be rate limited due to previous JWT
169/// authentication failures

Callers

nothing calls this directly

Calls 3

check_jwt_rate_limitFunction · 0.85
check_jwt_authFunction · 0.85
runMethod · 0.45

Tested by

no test coverage detected