ho una webapi e dovrei implementare un oauth 2.0 in c#

questo è il mio program 

"using Microsoft.EntityFrameworkCore;
using MicrosoftTeamsWebApiService.Hub;
using MicrosoftTeamsWebApiService.Models;
using System.Net;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddCors(options =>
{
    options.AddPolicy("AllowAllOrigins", policy =>
    {
        policy.AllowAnyOrigin()  // Permette tutte le origini
              .AllowAnyMethod()  // Permette tutti i metodi (GET, POST, etc.)
              .AllowAnyHeader(); // Permette tutte le intestazioni
    });
});

builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.Configure<AzureSettings>(builder.Configuration.GetSection("Azure"));
builder.Services.AddSignalR();
var app = builder.Build();


app.UseSwagger();
app.UseSwaggerUI();


app.UseHttpsRedirection();

app.UseAuthorization();
app.UseCors("AllowAllOrigins");
app.MapControllers();
app.MapHub<TeamsChatHub>("/teamsChatHub");

app.Run();
"

e questo è il mio controller 

"
using Azure.Core;
using Azure.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Options;
using Microsoft.Graph;
using Microsoft.Graph.Models;
using MicrosoftTeamsWebApiService.Hub;
using MicrosoftTeamsWebApiService.Models;
using Newtonsoft.Json;
using NuGet.Common;
using RestSharp;
using System.Net;
using System.Net.Http.Headers;
using System.Net.Http;
using System.Text;


namespace MicrosoftTeamsWebApiService.Controllers
{
    [Route("api/[controller]")]
    [ApiController]
    public class TeamsChatController : ControllerBase
    {
        private GraphServiceClient _graphClient;
        private IHubContext<TeamsChatHub> _hubContext;
        private IOptions<AzureSettings> _options;

        public TeamsChatController(IOptions<AzureSettings> options,IHubContext<TeamsChatHub> hubContext)
        {
             var clientSecretCredential = new ClientSecretCredential(options.Value.TenantId, options.Value.ClientId, options.Value.ClientSecret);
            _options = options;
            _graphClient = new GraphServiceClient(clientSecretCredential, new[] { ".default" });
            _hubContext = hubContext;
        }

        /// <summary>
        /// Recupera i dettagli di una chat esistente.
        /// https://learn.microsoft.com/en-us/graph/api/chat-get?view=graph-rest-1.0&tabs=http
        /// </summary>
        [HttpGet("{chatId}")]
        public async Task<Chat> GetChat(string chatId)
        {
            return await _graphClient.Chats[$"{chatId}"].GetAsync();
        }


        /// <summary>
        /// Recupera i messaggi di una chat esistente.
        /// https://learn.microsoft.com/en-us/graph/api/chat-list-messages?view=graph-rest-1.0&tabs=http
        /// </summary>
        [HttpGet("GetChatMessages/{chatId}")]
        public async Task<IActionResult> GetChatMessages(string chatId)
        {
            try
            {
                ChatMessageCollectionResponse chatMessageCollection = await _graphClient.Chats[chatId].Messages.GetAsync();
                return Ok(chatMessageCollection.Value); // Restituisce 200 OK con i messaggi
            }
            catch (Exception ex)
            {
                // Log dell'eccezione (opzionale)
                // _logger.LogError(ex, "Errore durante il recupero dei messaggi della chat.");

                // Restituisci una risposta 500
                return StatusCode(500, ex.Message);
            }
        }




        [HttpGet("RedirectAuth")]
        public async Task<string> RedirectAuth([FromQuery]string code, [FromQuery] string session_state)
        {
            
            var client = new RestClient();
            var request = new RestRequest($"https://login.microsoftonline.com/{_options.Value.TenantId}/oauth2/v2.0/token", Method.POST);
            request.AddHeader("Content-Type", "application/x-www-form-urlencoded");
            request.AddParameter("client_id", _options.Value.ClientId);
            request.AddParameter("grant_type", "authorization_code");
            request.AddParameter("code", code);
            request.AddParameter("redirect_uri", _options.Value.Endpoint + "/api/TeamsChat/RedirectAuth");
            request.AddParameter("scope", "https://graph.microsoft.com/.default");
            request.AddParameter("client_secret", _options.Value.ClientSecret);
            var response = await client.ExecuteAsync<AccessTokenResponse>(request);
            AccessTokenResponse accessTokenResponse = JsonConvert.DeserializeObject<AccessTokenResponse>(response.Content);
            _hubContext.Clients.All.SendAsync("access_token", accessTokenResponse.access_token);
            return "Chiudi pure la pagina";   
        }

        /// <summary>
        /// Crea una chat di gruppo chiedendo un titolo e la lista di utenti da aggiungere.
        /// https://learn.microsoft.com/en-us/graph/api/chat-post?view=graph-rest-1.0&tabs=http
        /// </summary>
        [HttpPost("CreateChat")]
        public async Task<Chat> CreateChat(ChatCreateInformation chatCreateInformation)
        {

            List<ConversationMember> chatMembers = new List<ConversationMember>();
            chatCreateInformation.ExecuterEmails.ToList().ForEach(executerEmail =>
            {
                chatMembers.Add(new AadUserConversationMember
                {
                    OdataType = "#microsoft.graph.aadUserConversationMember",
                    Roles = new List<string> { "owner", },
                    AdditionalData = new Dictionary<string, object> {
                        {
                            "user@odata.bind", $"https://graph.microsoft.com/v1.0/users('{executerEmail}')"
                        },
                    },
                });
            });
            Chat body = new Chat
            {
                ChatType = ChatType.Group,
                Topic = chatCreateInformation.Title,
                Members = chatMembers
            };

            return await _graphClient.Chats.PostAsync(body);

        }

        /// <summary>
        /// Aggiorna una chat esistente.(Si può aggiornare solo il titolo di una chat)
        /// https://learn.microsoft.com/en-us/graph/api/chat-patch?view=graph-rest-1.0&tabs=http
        /// </summary>
        [HttpPost("UpdateTitleChat")]
        public async Task<Chat> UpdateTitleChat(TitleChatUpdateInfo TitleChatUpdateInfo)
        {

            //Chat updatedChat = await graphClient.Chats[$"{TitleChatUpdateInfo.chatId}"].GetAsync();
            Chat updatedChat = new Chat
            {
                Topic = TitleChatUpdateInfo.Title
            };
            return await _graphClient.Chats[$"{TitleChatUpdateInfo.ChatId}"].PatchAsync(updatedChat);
        }

        [HttpPost("SendMessage")]
        public async Task<string> SendMessage(SendMessageModel sendMessageModel)
        {

            var message = new
            {
                body = new
                {
                    content = sendMessageModel.Message
                }
            };
            string jsonBody = JsonConvert.SerializeObject(message);
            var client = new RestClient("https://graph.microsoft.com/v1.0/chats/" + sendMessageModel.ChatId + "/messages");
            var request = new RestRequest(Method.POST);
            request.AddHeader("Authorization", "Bearer " + sendMessageModel.AccessToken);
            request.AddHeader("Content-Type", "application/json");
            request.AddParameter("application/json", jsonBody, ParameterType.RequestBody);

            var response = await client.ExecuteAsync<ChatMessage>(request);
            ChatMessageCollectionResponse ChatMessageCollection = await _graphClient.Chats[sendMessageModel.ChatId].Messages.GetAsync();
            ChatMessageCollection.Value.Reverse();
            _hubContext.Clients.All.SendAsync($"GetChatMessages{sendMessageModel.TaskId}", ChatMessageCollection.Value);
            return response.Content;

        }

        /// <summary>
        /// Rimuove tutti i membri di una chat esitente.
        /// (Get dei membri della chat) https://learn.microsoft.com/en-us/graph/api/chat-list-members?view=graph-rest-1.0&tabs=http
        /// (delete del singolo membro della chat)https://learn.microsoft.com/en-us/graph/api/chat-delete-members?view=graph-rest-1.0&tabs=http
        /// </summary>
        [HttpDelete("DeleteChatMembers/{chatId}")]
        public async Task<IActionResult> DeleteChatMembers(string chatId)
        {
            try
            {
                ConversationMemberCollectionResponse Members = await _graphClient.Chats[chatId].Members.GetAsync();
                // Creiamo una lista di task per le operazioni di cancellazione
                var tasks = new List<Task>();
                foreach (var member in Members.Value)
                {
                    tasks.Add(_graphClient.Chats[chatId].Members[member.Id].DeleteAsync());
                }
                // Aspettiamo che tutte le cancellazioni siano completate
                await Task.WhenAll(tasks);
                //Members.Value.ForEach(async (member) =>
                //{
                //    await _graphClient.Chats[chatId].Members[member.Id].DeleteAsync();
                //});
                return Ok("All Chat Member Deleted"); // Restituisce 200 OK con i messaggi
            }
            catch (Exception ex)
            {
                // Log dell'eccezione (opzionale)
                // _logger.LogError(ex, "Errore durante il recupero dei messaggi della chat.");

                // Restituisci una risposta 500
                return StatusCode(500, ex.Message);
            }



        }

    }
}
"

dovrei aggiungere il bearer token alle call già presenti