本文整理汇总了C#中Microsoft.Owin.Security.Infrastructure.AuthenticationTokenCreateContext.SerializeTicket方法的典型用法代码示例。如果您正苦于以下问题:C# AuthenticationTokenCreateContext.SerializeTicket方法的具体用法?C# AuthenticationTokenCreateContext.SerializeTicket怎么用?C# AuthenticationTokenCreateContext.SerializeTicket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Owin.Security.Infrastructure.AuthenticationTokenCreateContext
的用法示例。
在下文中一共展示了AuthenticationTokenCreateContext.SerializeTicket方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateAsync
public async Task CreateAsync(AuthenticationTokenCreateContext context)
{
var refreshTokenId = Guid.NewGuid().ToString("n");
using (AuthRepository _repo = new AuthRepository())
{
var token = new RefreshToken()
{
Id = refreshTokenId.GetHash(),
Subject = context.Ticket.Identity.Name,
IssuedUtc = DateTime.UtcNow,
ExpiresUtc = DateTime.UtcNow.AddMinutes(30)
};
context.Ticket.Properties.IssuedUtc = token.IssuedUtc;
context.Ticket.Properties.ExpiresUtc = token.ExpiresUtc;
token.ProtectedTicket = context.SerializeTicket();
var result = await _repo.AddRefreshToken(token);
if (result)
{
context.SetToken(refreshTokenId);
}
}
}
示例2: CreateAsync
public override async Task CreateAsync(AuthenticationTokenCreateContext context)
{
var guid = Guid.NewGuid().ToString();
var clientid = context.OwinContext.Get<string>("tm:client_id");
var refreshTokenLifeTime = context.OwinContext.Get<string>("tm:clientRefreshTokenLifeTime");
var token = new RefreshToken()
{
ID = HashingService.MakeHash(guid),
client_id = clientid,
username = context.Ticket.Identity.Name,
issued = DateTime.UtcNow,
expired = DateTime.UtcNow.AddMinutes(Convert.ToDouble(refreshTokenLifeTime))
};
context.Ticket.Properties.IssuedUtc = token.issued;
context.Ticket.Properties.ExpiresUtc = token.expired;
token.ProtectedTicket = context.SerializeTicket();
RefreshTokenService rts = new RefreshTokenService();
var result = await rts.AddRefreshToken(token);
if (result)
{
context.SetToken(guid);
}
}
示例3: CreateAsync
public async Task CreateAsync(AuthenticationTokenCreateContext context) {
var clientIdValue = context.Ticket.Properties.Dictionary["as:client_id"];
if (string.IsNullOrWhiteSpace(clientIdValue)) {
return;
}
int clientId = 0;
if (!int.TryParse(clientIdValue, out clientId)) {
return;
}
var token = Guid.NewGuid().ToString("n");
var refreshTokenLifeTime = context.OwinContext.Get<string>("as:clientRefreshTokenLifeTime");
var issuedUtc = DateTime.UtcNow;
var expiresUtc = DateTime.UtcNow.AddMinutes(Convert.ToDouble(refreshTokenLifeTime));
context.Ticket.Properties.IssuedUtc = issuedUtc;
context.Ticket.Properties.ExpiresUtc = expiresUtc;
var client = new AuthenticationClient();
var result = await client.SaveRefreshToken(new SaveRefreshTokenRequest {
HashedToken = PasswordHelper.HashToken(token),
ClientId = clientId,
Username = context.Ticket.Properties.Dictionary["userName"],
IssuedUtc = DateTime.UtcNow,
ExpiresUtc = DateTime.UtcNow.AddMinutes(Convert.ToDouble(refreshTokenLifeTime)),
ProtectedTicket = context.SerializeTicket()
});
if (result.IsSuccess) {
context.SetToken(token);
}
}
示例4: CreateAsync
public async Task CreateAsync(AuthenticationTokenCreateContext context)
{
var refreshTokenId = Guid.NewGuid().ToString("n");
using (var ctx = new ApplicationDbContext())
{
var token = new RefreshToken()
{
Id = Helper.GetHash(refreshTokenId),
Subject = context.Ticket.Identity.Name,
IssuedUtc = DateTime.UtcNow,
ExpiresUtc = DateTime.UtcNow.AddDays(30)
};
context.Ticket.Properties.IssuedUtc = token.IssuedUtc;
context.Ticket.Properties.ExpiresUtc = token.ExpiresUtc;
token.ProtectedTicket = context.SerializeTicket();
var result = await ctx.AddRefreshToken(token);
if (result)
{
context.SetToken(refreshTokenId);
}
}
}
示例5: CreateAsync
public async Task CreateAsync(AuthenticationTokenCreateContext context)
{
if (!context.OwinContext.Environment.ContainsKey(IS_REFREHTOKEN_EXPIRED_NAME) || (bool)context.OwinContext.Environment[IS_REFREHTOKEN_EXPIRED_NAME])
{
bool result = false;
var refreshTokenId = Guid.NewGuid().ToString("n");
var clientId = context.Ticket.Properties.Dictionary["audience"];
var refreshTokenLifetime = context.OwinContext.Get<string>("as:clientRefreshTokenLifeTime") ?? "30";
var token = new RefreshToken()
{
Id = Utilities.GetHash(refreshTokenId),
ClientId = clientId,
Subject = context.Ticket.Identity.Name,
IssuedUtc = DateTime.UtcNow,
ExpiresUtc = DateTime.UtcNow.AddDays(Double.Parse(refreshTokenLifetime))
};
context.Ticket.Properties.IssuedUtc = token.IssuedUtc;
context.Ticket.Properties.ExpiresUtc = token.ExpiresUtc;
token.ProtectedTicket = context.SerializeTicket();
using (IApplicationRepository rep = new ApplicationRepository())
{
result = await rep.RefreshTokens.AddAsync(token);
}
if (result)
{
context.SetToken(refreshTokenId);
}
}
}
示例6: CreateAsync
public async Task CreateAsync(AuthenticationTokenCreateContext context)
{
var clientId = context.Ticket.Properties.Dictionary["as:client_id"];
if (string.IsNullOrEmpty(clientId))
{
return;
}
var refreshTokenId = Guid.NewGuid().ToString("n");
var refreshTokenLifeTime = context.OwinContext.Get<string>("as:clientRefreshTokenLifeTime");
var token = new DataLayer.Entities.User.RefreshTokens()
{
refreshTokenId = SharedServices.HashingService.GetHash(refreshTokenId),
clientId = clientId,
subject = context.Ticket.Identity.Name,
issuedUTC = DateTime.UtcNow,
expiredUTC = DateTime.UtcNow.AddMinutes(Convert.ToDouble(refreshTokenLifeTime))
};
context.Ticket.Properties.IssuedUtc = token.issuedUTC;
context.Ticket.Properties.ExpiresUtc = token.expiredUTC;
token.protectedTicket = context.SerializeTicket();
var tokenObj = new BusinessLogic.Identity.RefreshTokens();
var result = await tokenObj.Insert(token);
if (result)
{
context.SetToken(refreshTokenId);
}
}
示例7: CreateAsync
public virtual async Task CreateAsync(AuthenticationTokenCreateContext context)
{
var clientId = context.Ticket.Properties.Dictionary["as:client_id"];
if (string.IsNullOrEmpty(clientId))
return;
var refreshTokenId = Guid.NewGuid().ToString("n");
await Task.Run(() => {
var refreshTokenLifeTime = context.OwinContext.Get<string>("as:clientRefreshTokenLifeTime");
var token = new OAuthRefreshToken()
{
Key = refreshTokenId.GenerateHash(),
ClientId = clientId,
Subject = context.Ticket.Identity.Name,
UserType = UserType.Name,
IssuedUtc = DateTime.UtcNow,
ExpiresUtc = DateTime.UtcNow.AddMinutes(Convert.ToDouble(refreshTokenLifeTime))
};
context.Ticket.Properties.IssuedUtc = token.IssuedUtc;
context.Ticket.Properties.ExpiresUtc = token.ExpiresUtc;
token.ProtectedTicket = context.SerializeTicket();
this._oauthStore.AddRefreshToken(token);
});
context.SetToken(refreshTokenId);
}
开发者ID:warrenbuckley,项目名称:UmbracoIdentity.OAuth,代码行数:33,代码来源:UmbracoIdentityOAuthRefreshTokenProvider.cs
示例8: CreateAsync
public async Task CreateAsync(AuthenticationTokenCreateContext context)
{
var clientid = context.Ticket.Properties.Dictionary["as:client_id"];
var refreshTokenLifetime = context.OwinContext.Get<string>("as:RefreshTokenLifetime");
var refreshTokenId = Guid.NewGuid().ToString("n");
if (string.IsNullOrEmpty(clientid))
{
return;
}
context.Ticket.Properties.IssuedUtc = DateTime.UtcNow;
context.Ticket.Properties.ExpiresUtc = DateTime.UtcNow.AddMinutes(Convert.ToDouble(refreshTokenLifetime));
var token = context.SerializeTicket();
var refreshDto = new RefreshTokenDto()
{
Id = refreshTokenId,
ClientId = clientid,
Subject = context.Ticket.Identity.Name,
Token = token
};
await _redisRepo.InsertRefreshTokenAsync(refreshDto);
context.SetToken(refreshTokenId);
}
示例9: CreateAsync
public async Task CreateAsync(AuthenticationTokenCreateContext context)
{
string clientid = context.Ticket.Properties.Dictionary["as:client_id"];
if (!string.IsNullOrEmpty(clientid))
{
string refreshTokenId = Guid.NewGuid().ToString("n");
UnityContainer unityContainer = UnityConfig.GetConfiguredContainer() as UnityContainer;
IRefreshTokenBll refreshTokenBll = UnityContainerExtensions.Resolve<IRefreshTokenBll>((IUnityContainer)unityContainer);
string refreshTokenLifeTime = context.OwinContext.Get<string>("as:clientRefreshTokenLifeTime");
RefreshToken token = new RefreshToken()
{
Id = ApplicationOAuthProvider.GetSecretHash(refreshTokenId),
ClientId = clientid,
Subject = context.Ticket.Identity.Name,
IssuedUtc = DateTime.UtcNow,
ExpiresUtc = DateTime.UtcNow.AddMinutes(Convert.ToDouble(refreshTokenLifeTime))
};
context.Ticket.Properties.IssuedUtc = new DateTimeOffset?((DateTimeOffset)token.IssuedUtc);
context.Ticket.Properties.ExpiresUtc = new DateTimeOffset?((DateTimeOffset)token.ExpiresUtc);
token.ProtectedTicket = context.SerializeTicket();
int result = await refreshTokenBll.InsertRefreshToken(token);
if (result > 0)
{
context.SetToken(refreshTokenId);
if (!string.IsNullOrEmpty(this.CurrentToken))
await this.LogHistory(LoginType.RefreshToken, LoginStatus.Success, clientid, token.Subject, this.CurrentToken, (string)null, (string)null);
}
else if (!string.IsNullOrEmpty(this.CurrentToken))
await this.LogHistory(LoginType.RefreshToken, LoginStatus.ErrorAddRefreshToken, clientid, token.Subject, this.CurrentToken, (string)null, (string)null);
}
}
示例10: CreateAsync
public async Task CreateAsync(AuthenticationTokenCreateContext context)
{
var clientId = context.Ticket.Properties.Dictionary["as:client_id"];
if (string.IsNullOrWhiteSpace(clientId))
{
return;
}
var refreshTokenId = Guid.NewGuid().ToString("N");
var refreshTokenLifetime = context.OwinContext.Get<string>("as:clientRefreshTokenLifetime");
var token = new RefreshToken
{
Id = AuthorizationHelpers.GetHash(refreshTokenId),
ClientApplicationId = clientId,
Subject = context.Ticket.Identity.Name,
IssuedAt = DateTime.UtcNow,
ExpiresAt = DateTime.UtcNow.AddMinutes(Convert.ToDouble(refreshTokenLifetime))
};
context.Ticket.Properties.IssuedUtc = token.IssuedAt;
context.Ticket.Properties.ExpiresUtc = token.ExpiresAt;
token.ProtectedTicket = context.SerializeTicket();
if (await _userRepository.TryAddRefreshTokenAsync(token))
{
context.SetToken(refreshTokenId);
}
}
示例11: CreateAsync
public async Task CreateAsync(AuthenticationTokenCreateContext context)
{
var clientid = context.Ticket.Properties.Dictionary["as:client_id"];
if (string.IsNullOrEmpty(clientid))
{
return;
}
var refreshTokenId = Guid.NewGuid().ToString("n");
//TODO: support multiple clients
//
//http://bitoftech.net/2014/07/16/enable-oauth-refresh-tokens-angularjs-app-using-asp-net-web-api-2-owin/
//https://github.com/thinktecture/Thinktecture.IdentityServer.v3/blob/1b33386e6ba29242293e20d806c2ad15a5bcf8ec/source/Core/Services/Default/DefaultRefreshTokenService.cs
// 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.Now.AddMinutes(1)
//};
//var refreshTokenTicket = new AuthenticationTicket(context.Ticket.Identity, refreshTokenProperties);
//_refreshTokens.TryAdd(guid, context.Ticket);
//_refreshTokens.TryAdd(guid, refreshTokenTicket);
context.Ticket.Properties.IssuedUtc = DateTime.Now;
context.Ticket.Properties.ExpiresUtc = new DateTimeOffset(DateTime.Now.AddDays(1));
context.SetToken(context.SerializeTicket());
//context.SetToken(refreshTokenTicket.ToString());
}
示例12: Create
public override void Create(AuthenticationTokenCreateContext context)
{
// Expiration time in seconds
int expire = 5 * 60;
context.Ticket.Properties.ExpiresUtc = new DateTimeOffset(DateTime.Now.AddSeconds(expire));
context.SetToken(context.SerializeTicket());
}
示例13: CreateAsync
/// <summary>
/// 创建RefreshToken,在客户端请求AccessToken的时候自动调用
/// </summary>
/// <param name="context"></param>
public async override Task CreateAsync(AuthenticationTokenCreateContext context)
{
string clientId = context.Ticket.Properties.Dictionary["as:client_id"];
if (string.IsNullOrEmpty(clientId))
{
return;
}
DateTime now = DateTime.UtcNow;
string userName = context.Ticket.Identity.Name;
if (clientId == userName)
{
return;
}
RefreshTokenInfo tokenInfo = new RefreshTokenInfo()
{
Value = Guid.NewGuid().ToString("N"),
IssuedUtc = now,
ExpiresUtc = now.AddDays(30),
UserName = userName,
ClientId = clientId
};
context.Ticket.Properties.IssuedUtc = tokenInfo.IssuedUtc;
context.Ticket.Properties.ExpiresUtc = tokenInfo.ExpiresUtc;
tokenInfo.ProtectedTicket = context.SerializeTicket();
if (await _clientRefreshTokenStore.SaveToken(tokenInfo))
{
context.SetToken(tokenInfo.Value);
}
}
示例14: Create
public override void Create(AuthenticationTokenCreateContext context)
{
if (context.Ticket.Identity.AuthenticationType == AuthenticationType.Anonymous) {
return;
}
//var authTicketService = ObjectFactory.GetInstance<AuthTicketService>();
var refreshToken = string.Empty;
while (true) {
refreshToken = GenerateRefreshToken();
if (true/*!authTicketService.Exists(x => x.Id == refreshToken)*/) {
break;
}
}
var clientId = context.Ticket.Properties.Dictionary["client_id"];
var authTicket = new AuthTicket() {
RefreshToken = refreshToken,
ResourceOwner = context.Ticket.Identity.FindFirst("Email").Value,
ClientId = context.Ticket.Properties.Dictionary["client_id"],
AccessToken = context.SerializeTicket(),
Issued = context.Ticket.Properties.IssuedUtc.Value.DateTime,
Expires = context.Ticket.Properties.ExpiresUtc.Value.DateTime
};
//authTicketService.Create(authTicket);
context.SetToken(authTicket.RefreshToken);
}
示例15: CreateAsync
public async Task CreateAsync(AuthenticationTokenCreateContext context)
{
var clientid = context.Ticket.Identity.Name;
var refreshTokenId = Guid.NewGuid().ToString("n");
var token = new RefreshToken()
{
Id = refreshTokenId,
ClientId = clientid,
IssuedUtc = DateTime.UtcNow,
ExpiresUtc = DateTime.UtcNow.AddSeconds(15)
};
context.Ticket.Properties.IssuedUtc = token.IssuedUtc;
context.Ticket.Properties.ExpiresUtc = token.ExpiresUtc;
token.ProtectedTicket = context.SerializeTicket();
repo.Add(refreshTokenId, token);
await Task.Delay(1);
context.SetToken(refreshTokenId);
//var allowedOrigins = context.OwinContext.Get<List<string>>("as:clientAllowedOrigins");
//context.OwinContext.Response.Headers.Add(
// "Access-Control-Allow-Origin",
// allowedOrigins.Select(x => x.ToString()).ToArray()
// //new[] { "*" }
// );
//context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
}