syntax = "proto3";

option go_package = "v1";
option java_package = "io.stackrox.proto.api.v1";

import "google/api/annotations.proto";
import "api/v1/common.proto";
import "api/v1/empty.proto";
import "storage/auth_provider.proto";

package v1;

message GetAuthProviderRequest {
    string id           = 1;
}

message GetAuthProvidersRequest {
    string name = 1;
    string type = 2;
}

message GetAuthProvidersResponse {
    repeated storage.AuthProvider auth_providers = 1;
}

message PostAuthProviderRequest {
    storage.AuthProvider provider = 1;
}

message UpdateAuthProviderRequest {
    string id = 1;

    oneof name_opt    {
        string name  = 2;
    }
    oneof enabled_opt {
        bool enabled = 3;
    }
}

message ExchangeTokenRequest {
    string external_token = 1;
    string type           = 2;
    string state          = 3;
}

message ExchangeTokenResponse {
    string token        = 1;
    string client_state = 2;
}

service AuthProviderService {
    rpc GetAuthProvider (GetAuthProviderRequest) returns (storage.AuthProvider) {
        option (google.api.http) = {
            get: "/v1/authProviders/{id}"
        };
    }

    rpc GetAuthProviders (GetAuthProvidersRequest) returns (GetAuthProvidersResponse) {
        option (google.api.http) = {
            get: "/v1/authProviders"
        };
    }

    rpc PostAuthProvider (PostAuthProviderRequest) returns (storage.AuthProvider) {
        option (google.api.http) = {
            post: "/v1/authProviders"
            body: "provider"
        };
    }

    rpc UpdateAuthProvider (UpdateAuthProviderRequest) returns (storage.AuthProvider) {
        option (google.api.http) = {
            patch: "/v1/authProviders/{id}"
            body: "*"
        };
    }

    rpc DeleteAuthProvider (ResourceByID) returns (Empty) {
        option (google.api.http) = {
            delete: "/v1/authProviders/{id}"
        };
    }

    rpc ExchangeToken (ExchangeTokenRequest) returns (ExchangeTokenResponse) {
        option (google.api.http) = {
            post: "/v1/authProviders/exchangeToken"
            body: "*"
        };
    }
}
