Auth endpoint
This commit is contained in:
parent
82d6eaa2a8
commit
269a23a8b7
5 changed files with 55 additions and 9 deletions
|
|
@ -1,5 +1,5 @@
|
|||
pub use burrowwebrpc::*;
|
||||
|
||||
mod burrowwebrpc {
|
||||
pub mod burrowwebrpc {
|
||||
tonic::include_proto!("burrowweb");
|
||||
}
|
||||
|
|
|
|||
41
burrow/src/auth/server/grpc_server.rs
Normal file
41
burrow/src/auth/server/grpc_server.rs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
use tonic::{Request, Response, Status};
|
||||
|
||||
use super::{
|
||||
grpc_defs::{
|
||||
burrowwebrpc::burrow_web_server::{BurrowWeb, BurrowWebServer},
|
||||
CreateDeviceRequest, CreateDeviceResponse, Empty, JwtInfo, ListDevicesResponse,
|
||||
SlackAuthRequest,
|
||||
},
|
||||
providers::slack::auth,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
struct BurrowGrpcServer;
|
||||
|
||||
#[tonic::async_trait]
|
||||
impl BurrowWeb for BurrowGrpcServer {
|
||||
async fn slack_auth(
|
||||
&self,
|
||||
request: Request<SlackAuthRequest>,
|
||||
) -> Result<Response<JwtInfo>, Status> {
|
||||
auth(request).await
|
||||
}
|
||||
|
||||
async fn create_device(
|
||||
&self,
|
||||
request: Request<CreateDeviceRequest>,
|
||||
) -> Result<Response<CreateDeviceResponse>, Status> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
async fn delete_device(&self, request: Request<JwtInfo>) -> Result<Response<Empty>, Status> {
|
||||
unimplemented!()
|
||||
}
|
||||
|
||||
async fn list_devices(
|
||||
&self,
|
||||
request: Request<JwtInfo>,
|
||||
) -> Result<Response<ListDevicesResponse>, Status> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
pub mod db;
|
||||
mod grpc_defs;
|
||||
pub mod grpc_defs;
|
||||
mod grpc_server;
|
||||
pub mod providers;
|
||||
|
||||
use anyhow::Result;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
pub mod slack;
|
||||
pub use super::db;
|
||||
pub use super::{db, grpc_defs};
|
||||
|
||||
#[derive(serde::Deserialize, Default, Debug)]
|
||||
pub struct OpenIdUser {
|
||||
|
|
|
|||
|
|
@ -8,17 +8,20 @@ use reqwest::header::AUTHORIZATION;
|
|||
use serde::Deserialize;
|
||||
|
||||
use super::db::store_connection;
|
||||
use super::grpc_defs::{JwtInfo, SlackAuthRequest};
|
||||
use tonic::{Request as TRequest, Response as TResponse, Result as TResult, Status as TStatus};
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct SlackToken {
|
||||
slack_token: String,
|
||||
}
|
||||
pub async fn auth(Json(payload): Json<SlackToken>) -> (StatusCode, String) {
|
||||
let slack_user = match fetch_slack_user(&payload.slack_token).await {
|
||||
pub async fn auth(request: TRequest<SlackAuthRequest>) -> TResult<TResponse<JwtInfo>, TStatus> {
|
||||
let slack_token = request.into_inner().slack_token;
|
||||
let slack_user = match fetch_slack_user(&slack_token).await {
|
||||
Ok(user) => user,
|
||||
Err(e) => {
|
||||
log::error!("Failed to fetch Slack user: {:?}", e);
|
||||
return (StatusCode::UNAUTHORIZED, String::new());
|
||||
return Err(TStatus::unauthenticated("Failed to fetch slack user"));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -28,15 +31,16 @@ pub async fn auth(Json(payload): Json<SlackToken>) -> (StatusCode, String) {
|
|||
slack_user.sub
|
||||
);
|
||||
|
||||
let conn = match store_connection(slack_user, "slack", &payload.slack_token, None) {
|
||||
let conn = match store_connection(slack_user, "slack", &slack_token, None) {
|
||||
Ok(user) => user,
|
||||
Err(e) => {
|
||||
log::error!("Failed to fetch Slack user: {:?}", e);
|
||||
return (StatusCode::UNAUTHORIZED, String::new());
|
||||
return Err(TStatus::unauthenticated("Failed to store connection"));
|
||||
}
|
||||
};
|
||||
|
||||
(StatusCode::OK, String::new())
|
||||
// TODO
|
||||
Ok(TResponse::new(JwtInfo { jwt: "TODO".into() }))
|
||||
}
|
||||
|
||||
async fn fetch_slack_user(access_token: &str) -> Result<super::OpenIdUser> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue