Add authentication #1
					 2 changed files with 3 additions and 12 deletions
				
			
		secret as string and not bytes
				commit
				
					
					
						853b760968
					
				
			
		| 
						 | 
					@ -20,20 +20,11 @@ pub struct DnsConfig {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Debug, Deserialize)]
 | 
					#[derive(Debug, Deserialize)]
 | 
				
			||||||
pub struct WebAppConfig {
 | 
					pub struct WebAppConfig {
 | 
				
			||||||
    #[serde(deserialize_with = "from_base64")]
 | 
					    pub secret: String,
 | 
				
			||||||
    pub secret: Vec<u8>,
 | 
					 | 
				
			||||||
    #[serde(deserialize_with = "from_duration")]
 | 
					    #[serde(deserialize_with = "from_duration")]
 | 
				
			||||||
    pub token_duration: Duration,
 | 
					    pub token_duration: Duration,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
fn from_base64<'de, D>(deserializer: D) -> Result<Vec<u8>, D::Error>
 | 
					 | 
				
			||||||
    where D: Deserializer<'de>
 | 
					 | 
				
			||||||
{
 | 
					 | 
				
			||||||
    use serde::de::Error;
 | 
					 | 
				
			||||||
    String::deserialize(deserializer)
 | 
					 | 
				
			||||||
        .and_then(|string| base64::decode(&string).map_err(|err| Error::custom(err.to_string())))
 | 
					 | 
				
			||||||
}
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
fn from_duration<'de, D>(deserializer: D) -> Result<Duration, D::Error>
 | 
					fn from_duration<'de, D>(deserializer: D) -> Result<Duration, D::Error>
 | 
				
			||||||
    where D: Deserializer<'de>
 | 
					    where D: Deserializer<'de>
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -200,7 +200,7 @@ impl AuthClaims {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    pub fn encode(self, secret: &[u8]) -> JwtResult<String> {
 | 
					    pub fn encode(self, secret: &str) -> JwtResult<String> {
 | 
				
			||||||
        encode(&Header::default(), &self, &EncodingKey::from_secret(&secret))
 | 
					        encode(&Header::default(), &self, &EncodingKey::from_secret(secret.as_bytes()))
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue