| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using System;
- using System.Collections.Concurrent;
- using System.Threading.Tasks;
- using Abp.Dependency;
- using Microsoft.Owin.Security;
- using Microsoft.Owin.Security.Infrastructure;
- namespace WeEngine.Api.Providers
- {
- public class IwbRefreshTokenProvider : IAuthenticationTokenProvider, ITransientDependency
- {
- private static ConcurrentDictionary<string, AuthenticationTicket> _refreshTokens = new ConcurrentDictionary<string, AuthenticationTicket>();
- public Task CreateAsync(AuthenticationTokenCreateContext context)
- {
- var guid = Guid.NewGuid().ToString("N");
- // maybe only create a handle the first time, then re-use for same client
- // copy properties and set the desired lifetime of refresh token
- var refreshTokenProperties = new AuthenticationProperties(context.Ticket.Properties.Dictionary)
- {
- IssuedUtc = context.Ticket.Properties.IssuedUtc,
- ExpiresUtc = DateTime.UtcNow.AddYears(1)
- };
- var refreshTokenTicket = new AuthenticationTicket(context.Ticket.Identity, refreshTokenProperties);
- //_refreshTokens.TryAdd(guid, context.Ticket);
- _refreshTokens.TryAdd(guid, refreshTokenTicket);
- // consider storing only the hash of the handle
- context.SetToken(guid);
- return Task.FromResult<object>(null);
- }
- public Task ReceiveAsync(AuthenticationTokenReceiveContext context)
- {
- AuthenticationTicket ticket;
- if (_refreshTokens.TryRemove(context.Token, out ticket))
- {
- context.SetTicket(ticket);
- }
- return Task.FromResult<object>(null);
- }
- public void Create(AuthenticationTokenCreateContext context)
- {
- throw new NotImplementedException();
- }
- public void Receive(AuthenticationTokenReceiveContext context)
- {
- throw new NotImplementedException();
- }
- }
- }
|