本文整理汇总了C#中Microsoft.Owin.Security.Infrastructure.AuthenticationTokenCreateContext类的典型用法代码示例。如果您正苦于以下问题:C# AuthenticationTokenCreateContext类的具体用法?C# AuthenticationTokenCreateContext怎么用?C# AuthenticationTokenCreateContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AuthenticationTokenCreateContext类属于Microsoft.Owin.Security.Infrastructure命名空间,在下文中一共展示了AuthenticationTokenCreateContext类的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 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 RefreshToken()
{
Id = HashMaker.GetHash(refreshTokenId),
ClientId = clientid,
Subject = context.Ticket.Identity.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();
var result = await authRepository.AddRefreshToken(token);
if (result)
{
context.SetToken(refreshTokenId);
}
}
示例3: CreateAsync
public async Task CreateAsync(AuthenticationTokenCreateContext context)
{
var clientId = context.Ticket.Properties.Dictionary["client_id"];
if (string.IsNullOrEmpty(clientId))
{
return;
}
var refreshTokenId = Guid.NewGuid().ToString("n");
var token = new RefreshToken
{
Id = refreshTokenId,
ClientId = clientId,
Subject = context.Ticket.Identity.Name,
IssuedUtc = DateTime.UtcNow,
ExpiresUtc =
DateTime.UtcNow.AddHours(
Convert.ToInt32(WebConfigurationManager.AppSettings["RefreshTokenExpiration"]))
};
context.Ticket.Properties.IssuedUtc = token.IssuedUtc;
context.Ticket.Properties.ExpiresUtc = token.ExpiresUtc;
token.ProtectedTicket = context.SerializeTicket();
//TODO: store the token somewhere
context.SetToken(refreshTokenId);
}
示例4: 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);
}
}
示例5: 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());
}
示例6: 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);
}
示例7: CreateAsync
public Task CreateAsync(AuthenticationTokenCreateContext context)
{
return Task.Run(() =>
{
Create(context);
});
}
示例8: 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);
}
}
示例9: 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[] { "*" });
}
示例10: Create
public void Create(AuthenticationTokenCreateContext context)
{
var clientid = context.OwinContext.Get<string>("as:client_id");
if (string.IsNullOrEmpty(clientid))
{
return;
}
var appTokenId = Guid.NewGuid().ToString("n");
var appTokenService = mobSocialEngine.ActiveEngine.Resolve<IAppTokenService>();
var tokenLifeTime = context.OwinContext.Get<string>("as:clientAccessTokenLifeTime");
var token = new AppToken() {
Guid = Helper.GetHash(appTokenId),
ClientId = clientid,
Subject = context.Ticket.Identity.Name,
IssuedUtc = DateTime.UtcNow,
ExpiresUtc = DateTime.UtcNow.AddMinutes(Convert.ToDouble(tokenLifeTime)),
TokenType = TokenType.AccessToken
};
context.Ticket.Properties.IssuedUtc = token.IssuedUtc;
context.Ticket.Properties.ExpiresUtc = token.ExpiresUtc;
token.ProtectedTicket = context.SerializeTicket();
appTokenService.Insert(token);
context.SetToken(appTokenId);
}
示例11: 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);
}
}
示例12: 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());
}
示例13: 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);
}
}
}
示例14: 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);
}
}
示例15: 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