syntax = "proto3";
package auth;

// import "prelude.proto";
import "google/protobuf/empty.proto";

// token | id | date_created | user_agent | ip | uid
//  |       |         |           |               |
//   \ Client token   |            \ HTTP request UserAgent to fingerprint check
//          |         |                           |
//           \ ID to identify the token            \ User ID
//                    |
//                     \ datetime when the token has created

// let auth = HashMap<(Token, AuthObject)>;
// type Token = u32;
// struct AuthObject {
//   id: u32,
//   token: String,
//   user_agent: String,
//   ip: IpAddress,
//   created_at: DateTime<Utc>,
//   created_by: u32,
// }

service Auth {
  // Authenticates a given token
  rpc Authenticate(AuthRequest) returns (AuthObject);
  // Creates a token and stores it
  rpc CreateToken(CreateTokenRequest) returns (google.protobuf.Empty);
  // Removes a given token
  rpc RemoveToken(e) returns (google.protobuf.Empty);
  // Force logout a given UID
  rpc ForceLogout(ForceLogoutRequest) returns (google.protobuf.Empty);
}

message e {}

message AuthRequest {
  // Check if token exists and signature valid
  uint32 token = 1;
  // Fingerprint validation
  string user_agent = 2;
}

message AuthObject {
  uint32 token = 1;
  uint32 uid = 2;
  string logged_in = 3;
}

message CreateTokenRequest {
  uint32 uid = 1;
  string client_user_agent = 2;
  string created_ip_address = 3;
  uint32 created_by = 4;
}

message RemoveTokenRequest { string token = 1; }

message ForceLogoutRequest { uint32 uid = 1; }