Bypass auth requirement for first time flow
This commit is contained in:
parent
f90a98d231
commit
3ed2c75b30
1 changed files with 13 additions and 7 deletions
20
src/api.rs
20
src/api.rs
|
@ -174,13 +174,20 @@ impl Handler for AuthHandler {
|
||||||
{
|
{
|
||||||
let mut auth_success = false;
|
let mut auth_success = false;
|
||||||
|
|
||||||
|
// Skip auth for first time setup
|
||||||
|
if user::count(self.db.deref())? == 0 {
|
||||||
|
auth_success = true;
|
||||||
|
}
|
||||||
|
|
||||||
// Auth via Authorization header
|
// Auth via Authorization header
|
||||||
if let Some(auth) = req.headers.get::<Authorization<Basic>>() {
|
if !auth_success {
|
||||||
if let Some(ref password) = auth.password {
|
if let Some(auth) = req.headers.get::<Authorization<Basic>>() {
|
||||||
auth_success =
|
if let Some(ref password) = auth.password {
|
||||||
user::auth(self.db.deref(), auth.username.as_str(), password.as_str())?;
|
auth_success =
|
||||||
req.extensions
|
user::auth(self.db.deref(), auth.username.as_str(), password.as_str())?;
|
||||||
.insert::<SessionKey>(Session { username: auth.username.clone() });
|
req.extensions
|
||||||
|
.insert::<SessionKey>(Session { username: auth.username.clone() });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -193,7 +200,6 @@ impl Handler for AuthHandler {
|
||||||
if !auth_success {
|
if !auth_success {
|
||||||
return Err(Error::from(ErrorKind::AuthenticationRequired).into());
|
return Err(Error::from(ErrorKind::AuthenticationRequired).into());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
self.handler.handle(req)
|
self.handler.handle(req)
|
||||||
|
|
Loading…
Add table
Reference in a new issue