本文整理汇总了C#中Microsoft.Owin.Security.Infrastructure.AuthenticationTokenCreateContext类的典型用法代码示例。如果您正苦于以下问题:C# AuthenticationTokenCreateContext类的具体用法?C# AuthenticationTokenCreateContext怎么用?C# AuthenticationTokenCreateContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AuthenticationTokenCreateContext类属于Microsoft.Owin.Security.Infrastructure命名空间,在下文中一共展示了AuthenticationTokenCreateContext类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
}
}
开发者ID:jasonoiu,项目名称:MvcExtend,代码行数:29,代码来源:SimpleRefreshTokenProvider.cs
示例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);
}
}
开发者ID:NerdCats,项目名称:TaskCat,代码行数:33,代码来源:TaskCatRefreshTokenProvider.cs
示例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);
}
开发者ID:eddievagabond,项目名称:angular-oauth-base,代码行数:31,代码来源:CustomOAuthRefreshProvider.cs
示例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);
}
}
开发者ID:tadmcclellan,项目名称:SEAM,代码行数:30,代码来源:SecRefreshTokenPovider.cs
示例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());
}
开发者ID:Meilu,项目名称:Flight.api,代码行数:7,代码来源:RefreshTokenProvider.cs
示例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);
}
开发者ID:cemkurtulus,项目名称:ck-oauth,代码行数:28,代码来源:RefreshTokenProvider.cs
示例7: CreateAsync
public Task CreateAsync(AuthenticationTokenCreateContext context)
{
return Task.Run(() =>
{
Create(context);
});
}
开发者ID:szahn,项目名称:AngularWebApiOAuthDemo,代码行数:7,代码来源:OAuthRefreshTokenProvider.cs
示例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);
}
}
开发者ID:i66soft,项目名称:osharp,代码行数:34,代码来源:OsharpRefreshTokenProvider.cs
示例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[] { "*" });
}
开发者ID:Liteolika,项目名称:WebAuth,代码行数:32,代码来源:SimpleRefreshTokenProvider.cs
示例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);
}
开发者ID:Console-Byte,项目名称:mobsocial,代码行数:33,代码来源:ApplicationAuthorizationCodeProvider.cs
示例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);
}
}
开发者ID:kdewal,项目名称:kym,代码行数:34,代码来源:SimpleRefreshTokenProvider.cs
示例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());
}
开发者ID:uwe-e,项目名称:BSE.Tunes,代码行数:32,代码来源:AuthenticationTokenProvider.cs
示例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);
}
}
}
开发者ID:dsoverby1986,项目名称:HouseholdBudgeter,代码行数:29,代码来源:RefreshTokenProvider.cs
示例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);
}
}
开发者ID:innercitypressure,项目名称:ngKeyBase,代码行数:33,代码来源:RefreshTokenProvider.cs
示例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
示例16: 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);
}
}
开发者ID:quangnc0503h,项目名称:ecommerce,代码行数:31,代码来源:SimpleRefreshTokenProvider.cs
示例17: 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);
}
开发者ID:pplavetzki,项目名称:LanguageExchange,代码行数:28,代码来源:RefreshTokenProvider.cs
示例18: 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);
}
}
开发者ID:huoxudong125,项目名称:Moviepicker,代码行数:29,代码来源:SimpleRefreshTokenProvider.cs
示例19: Create
/// <summary>
///
/// </summary>
/// <param name="context"></param>
public void Create(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 AuthenticationRefreshToken
{
Id = HelperMethods.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();
AuthenticationRefreshTokenService.Save(token);
context.SetToken(refreshTokenId);
}
开发者ID:truller2010,项目名称:KotikoBlog,代码行数:35,代码来源:SimpleRefreshTokenProvider.cs
示例20: 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);
}
}
}
开发者ID:Fanuer,项目名称:EventCorp,代码行数:32,代码来源:CustomRefreshTokenProvider.cs
注:本文中的Microsoft.Owin.Security.Infrastructure.AuthenticationTokenCreateContext类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论