fn authenticate(&self, conn: &PgConnection) -> AppResult<AuthenticatedUser> {
        if let Some(id) = self.extensions().find::<TrustedUserId>() {
            // A trusted user_id was provided by a signed cookie (or a test `MockCookieUser`)
            Ok(AuthenticatedUser {
                user_id: id.0,
                token_id: None,
            })
        } else {
            // Otherwise, look for an `Authorization` header on the request
            if let Some(headers) = self.headers().find("Authorization") {
                ApiToken::find_by_api_token(conn, headers[0])
                    .map(|token| AuthenticatedUser {
                        user_id: token.user_id,
                        token_id: Some(token.id),
                    })
                    // Convert a NotFound (or other database error) into Unauthorized
                    .map_err(|_| Box::new(Unauthorized) as Box<dyn AppError>)
            } else {
                // Unable to authenticate the user
                Err(Box::new(Unauthorized))
            }
        }
    }
/// Obtain `AuthenticatedUser` for the request or return an `Unauthorized` error
Obtain `AuthenticatedUser` for the request or return an `Unauthorized` error
Obtain ` AuthenticatedUser ` for the request or return an ` Unauthorized ` error
fn authenticate(&self, conn: &PgConnection) -> AppResult<AuthenticatedUser> {
        if let Some(id) = self.extensions().find::<TrustedUserId>() {
            // A trusted user_id was provided by a signed cookie (or a test `MockCookieUser`)
            Ok(AuthenticatedUser {
                user_id: id.0,
                token_id: None,
            })
        } else {
            // Otherwise, look for an `Authorization` header on the request
            if let Some(headers) = self.headers().find("Authorization") {
                ApiToken::find_by_api_token(conn, headers[0])
                    .map(|token| AuthenticatedUser {
                        user_id: token.user_id,
                        token_id: Some(token.id),
                    })
                    // Convert a NotFound (or other database error) into Unauthorized
                    .map_err(|_| Box::new(Unauthorized) as Box<dyn AppError>)
            } else {
                // Unable to authenticate the user
                Err(Box::new(Unauthorized))
            }
        }
    }
fn authenticate ( & self , conn : & PgConnection ) -> AppResult < AuthenticatedUser > { if let Some ( id ) = self . extensions ( ) . find :: < TrustedUserId > ( ) { // A trusted user_id was provided by a signed cookie (or a test `MockCookieUser`) Ok ( AuthenticatedUser { user_id : id . 0 , token_id : None , } ) } else { // Otherwise, look for an `Authorization` header on the request if let Some ( headers ) = self . headers ( ) . find ( " " ) { ApiToken :: find_by_api_token ( conn , headers [ 0 ] ) . map ( | token | AuthenticatedUser { user_id : token . user_id , token_id : Some ( token . id ) , } ) // Convert a NotFound (or other database error) into Unauthorized . map_err ( | _ | Box :: new ( Unauthorized ) as Box < dyn AppError > ) } else { // Unable to authenticate the user Err ( Box :: new ( Unauthorized ) ) } } }
Obtain `AuthenticatedUser` for the request or return an `Unauthorized` error
Obtain ` AuthenticatedUser ` for the request or return an ` Unauthorized ` error
&self
conn
&PgConnection