Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return entity slug with confirmation endpoint #279

Merged
merged 1 commit into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ $ curl -w "\n" -X POST http://127.0.0.1:5433/v1/register -H "entity-type: user"

$ curl -w "\n" -X POST http://127.0.0.1:5433/v1/confirm -H "authentication-token: TOKEN_FROM_EMAIL"

{"token":"<API_TOKEN>"}
{"entity":"marcua","token":"<API_TOKEN>"}

$ curl -w "\n" -X POST http://127.0.0.1:5433/v1/marcua/test.sqlite/create -H "db-type: sqlite" -H "authorization: Bearer <API_TOKEN_FROM_PREVIOUS_COMMAND>"

Expand Down
4 changes: 2 additions & 2 deletions src/bin/ayb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ async fn main() -> std::io::Result<()> {
.insert(url.clone(), api_token.token.clone());
config.to_file(&config_path)?;
println!(
"Successfully authenticated and saved token {}",
api_token.token
"Successfully authenticated {} and saved token {}",
api_token.entity, api_token.token
);
}
Err(err) => {
Expand Down
1 change: 1 addition & 0 deletions src/http/endpoints/confirm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ async fn confirm(
let (api_token, token_string) = generate_api_token(&created_entity)?;
let _ = ayb_db.create_api_token(&api_token).await?;
let returned_token = APIAPIToken {
entity: created_entity.slug,
token: token_string,
};

Expand Down
1 change: 1 addition & 0 deletions src/http/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ pub struct AuthenticationDetails {

#[derive(Debug, Serialize, Deserialize)]
pub struct APIToken {
pub entity: String,
pub token: String,
}

Expand Down
4 changes: 2 additions & 2 deletions tests/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ pub struct EmailEntry {

pub fn extract_api_key(output: &Output) -> Result<String, AybError> {
let output_str = std::str::from_utf8(&output.stdout)?;
let re = Regex::new(r"^Successfully authenticated and saved token (\S+)\n").unwrap();
let re = Regex::new(r"^Successfully authenticated (\S+) and saved token (\S+)\n").unwrap();
if re.is_match(output_str) {
let captures = re.captures(output_str).unwrap();
Ok(captures.get(1).map_or("", |m| m.as_str()).to_string())
Ok(captures.get(2).map_or("", |m| m.as_str()).to_string())
} else {
Err(AybError::Other {
message: "No API key".to_string(),
Expand Down