コード例 #1
0
        // [Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
        public async Task <ActionResult> GetCalender(string userName)
        {
            try
            {
                if (string.IsNullOrEmpty(userName))
                {
                    return(BadRequest("Username is required"));
                }

                AuthToken authToken = await _authTokenRepo.GetTokensForNameAsync(userName);

                if (authToken == null)
                {
                    return(NotFound("User not found"));
                }

                // Get Key
                var filesResponse = await _googleCalendarApi.ListFiles(authToken.Token, authToken.RefreshToken, async token =>
                {
                    AuthToken @event  = await _authTokenRepo.GetTokensForNameAsync(userName);
                    dynamic response  = JsonConvert.DeserializeObject(token);
                    @event.Token      = response.access_token;
                    @event.ExpireDate = DateTime.Now.AddSeconds((int)response.expires_in);

                    await _authTokenRepo.UpdateTokenAsync(@event);
                });

                return(Ok(filesResponse));
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                return(BadRequest("Unable to get user calendar"));
            }
        }