Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="clientId"></param>
        /// <param name="client"></param>
        /// <returns></returns>
        private OauRefreshToken GetRefreshToken(AuthenticationTokenCreateContext context, string clientId, OauClient client)
        {
            var identity = context.Ticket.Identity;

            if (identity == null)
            {
                return(null);
            }
            int    userId          = 0;
            string userName        = identity.Name;
            string customTokenType = string.Empty;
            //var userExtInfo = context.OwinContext.Get<string>("as:userExtInfo");
            //string deviceId = context.OwinContext.Get<string>("as:deviceId");
            //string customTokenType = context.OwinContext.Get<string>("as:customTokenType");
            //if (string.IsNullOrEmpty(customTokenType))
            //{
            //    customTokenType = identity.AuthenticationType;
            //}
            //if (userId < 1 && identity.Claims != null)
            //{
            //    var tmpUserId = identity.Claims.FirstOrDefault(a => a.Type == ClaimTypes.PrimarySid);
            //    if (tmpUserId != null)
            //    {
            //        userId = Convert.ToInt32(tmpUserId.Value);
            //    }
            //}
            //if (string.IsNullOrEmpty(userExtInfo) && identity.Claims != null)
            //{
            //    var tmpUserData = identity.Claims.FirstOrDefault(a => a.Type == ClaimTypes.UserData);
            //    if (tmpUserData != null)
            //    {
            //        userExtInfo = tmpUserData.Value;
            //    }
            //}
            var refreshTokenId = Guid.NewGuid().ToString("n");
            var refreshToken   = new OauRefreshToken()
            {
                AppId           = clientId,
                ExpiresUtc      = DateTime.UtcNow.AddMinutes(client.RefreshTokenLifeTime),
                IssuedUtc       = DateTime.UtcNow,
                ProtectedTicket = context.SerializeTicket(),
                RefreshToken    = refreshTokenId,
                TokenType       = identity.AuthenticationType,
                UserName        = userName,
                UserID          = userId,
                CustomTokenType = customTokenType,
                AccessToken     = string.Empty
            };

            return(refreshToken);
        }
Esempio n. 2
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="refreshToken"></param>
 /// <returns></returns>
 private Task <int> HandleCreateToken(OauRefreshToken refreshToken)
 {
     return(Task.FromResult(new Random().Next(10000, 99999)));
 }