// Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0

syntax = "proto3";

package auth.v1;
option go_package = "github.com/absmach/magistrala/api/grpc/auth/v1";

// AuthService is a service that provides authentication
// and authorization functionalities for Magistrala services.
service AuthService {
  rpc Authorize(AuthZReq) returns (AuthZRes) {}
  rpc Authenticate(AuthNReq) returns (AuthNRes) {}
}


message AuthNReq {
  string token = 1;
}

message AuthNRes {
  string id = 1;
  string user_id = 2;
  uint32 user_role = 3;
  bool verified = 4;
  uint32 token_type = 5;
}

message PolicyReq {
  string domain = 1;
  string subject_type = 2;
  string subject_kind = 3;
  string subject_relation = 4;
  string subject = 5;
  string relation = 6;
  string permission = 7;
  string object = 8;
  string object_type = 9;
}

message PATReq {
  string pat_id = 1;
  string domain = 2;
  string operation = 3;
  string user_id = 4;
  string entity_id = 5;
  string entity_type = 6;
}

message AuthZReq {
  PolicyReq policy_req = 1;
  optional PATReq pat_req = 2;
}

message AuthZRes {
  bool authorized = 1;
  string id = 2;
}
