【问题标题】:full calendar io events as json feed add bearer token完整的日历 io 事件作为 json 提要添加不记名令牌
【发布时间】:2023-01-20 05:20:42
【问题描述】:

我使用完整的日历 io 事件作为 json 提要来调用 .net 6 web api。

客户端反应代码

<FullCalendar
        initialView="dayGridMonth"
        headerToolbar={{
          left: "prev,next",
          center: "title",
          right: "dayGridMonth,timeGridWeek,timeGridDay"
        }}
        plugins={[dayGridPlugin, timeGridPlugin]}
        events={`${process.env.REACT_APP_API_URL}/activities/getEventsByDate/${id}`}
        eventClick={handleEventClick}
      />

.net 6 网络 API 控制器。

  [AllowAnonymous]
        [HttpGet("GetEventsByDate/{routeName}")]
        public async Task<ActionResult> GetRoomEvents(string routeName)
        {
            string start = Request.Query["start"];
            string end = Request.Query["end"];
            return HandleResult(await Mediator.Send(new GetEventsByDate.Query { RouteName = routeName, Start = start, End = end }));
        }

但是我想删除 AllowAnonymous 并添加我的 jwt 不记名令牌。他们是否可以选择使用完整的日历 io json 提要来做到这一点?

【问题讨论】:

标签: reactjs fullcalendar asp.net-core-webapi


【解决方案1】:

使用 Typescript,您可以使用以下方法获取添加了令牌的 api:

 events: function (info, successCallback, failureCallback) {
            const response = fetch('api/calendar', {
                method: 'GET',
                headers: {
                    "Authorization": 'Bearer ' + token)
                }
            });
            const data = response;
         successCallback(data);
         failureCallback(data);
        },
    }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多