summaryrefslogtreecommitdiffstats
path: root/rust/src/auth.rs
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@robocracy.org>2018-12-31 13:20:02 -0800
committerBryan Newbold <bnewbold@robocracy.org>2018-12-31 13:20:02 -0800
commitf9c15a4fc22cb87179e459a283146769e612a92b (patch)
tree0f82f216fa17a2178b766d0af76cb8be7657ddee /rust/src/auth.rs
parent8a6ab2ed76d725e6e8d47e51572f009407ed5ca2 (diff)
downloadfatcat-f9c15a4fc22cb87179e459a283146769e612a92b.tar.gz
fatcat-f9c15a4fc22cb87179e459a283146769e612a92b.zip
wire-up auth config via ENV
Diffstat (limited to 'rust/src/auth.rs')
-rw-r--r--rust/src/auth.rs20
1 files changed, 15 insertions, 5 deletions
diff --git a/rust/src/auth.rs b/rust/src/auth.rs
index 0fe21ebe..450a19d6 100644
--- a/rust/src/auth.rs
+++ b/rust/src/auth.rs
@@ -40,22 +40,24 @@ pub struct AuthConfectionary {
}
impl AuthConfectionary {
- pub fn new(location: String, identifier: String, key: Vec<u8>) -> AuthConfectionary {
+ pub fn new(location: String, identifier: String, key_base64: String) -> Result<AuthConfectionary> {
+ let key = BASE64.decode(key_base64.as_bytes())?;
let mut root_keys = HashMap::new();
root_keys.insert(identifier.clone(), key.clone());
- AuthConfectionary {
+ Ok(AuthConfectionary {
location: location,
identifier: identifier,
key: key,
root_keys: root_keys,
- }
+ })
}
pub fn new_dummy() -> AuthConfectionary {
AuthConfectionary::new(
"test.fatcat.wiki".to_string(),
"dummy".to_string(),
- DUMMY_KEY.to_vec())
+ BASE64.encode(DUMMY_KEY),
+ ).unwrap()
}
pub fn create_token(&self, editor_id: FatCatId, expires: Option<DateTime<Utc>>) -> Result<String> {
@@ -180,7 +182,15 @@ impl AuthConfectionary {
}
}
-pub fn revoke_tokens(conn: &DbConn, editor_id: FatCatId) -> Result<()>{
+pub fn create_key() -> String {
+ let mut key: Vec<u8> = vec![0; 32];
+ for v in key.iter_mut() {
+ *v = rand::random()
+ }
+ BASE64.encode(&key)
+}
+
+pub fn revoke_tokens(conn: &DbConn, editor_id: FatCatId) -> Result<()> {
diesel::update(editor::table.filter(editor::id.eq(&editor_id.to_uuid())))
.set(editor::auth_epoch.eq(Utc::now()))
.execute(conn)?;