本文整理汇总了C#中Microsoft.Owin.Security.Infrastructure.AuthenticationTokenReceiveContext.SetTicket方法的典型用法代码示例。如果您正苦于以下问题:C# AuthenticationTokenReceiveContext.SetTicket方法的具体用法?C# AuthenticationTokenReceiveContext.SetTicket怎么用?C# AuthenticationTokenReceiveContext.SetTicket使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Owin.Security.Infrastructure.AuthenticationTokenReceiveContext
的用法示例。
在下文中一共展示了AuthenticationTokenReceiveContext.SetTicket方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReceiveAsync
public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
{
//PIN lockout not yet implemented. Might integrated with account lockout or its own thing
//Uncomment this to accept a post parameter called "pin"
//IFormCollection form = await context.Request.ReadFormAsync();
//string submittedPin = form["PIN"];
if(!String.IsNullOrEmpty(context.Token)){
Guid refreshToken = Guid.Parse(context.Token);
if(refreshToken != null){
ApplicationDbContext dbContext = context.OwinContext.Get<ApplicationDbContext>();
OAuthSession oauthSession = dbContext.OAuthSessions.SingleOrDefault(oas => oas.RefreshToken == refreshToken);
OAuthClient oauthClient = context.OwinContext.Get<OAuthClient>(NicksApplicationOAuthProvider.OwinClientKey);
if (oauthSession != null && oauthClient != null && oauthSession.ClientId == oauthClient.Id && oauthClient.OrganizationId == oauthSession.OrganizationId && oauthSession.IsRefreshTokenValid(refreshToken, Startup.RefreshTokenTimeSpan))
{
ApplicationUserManager userManager = context.OwinContext.GetUserManager<ApplicationUserManager>();
ApplicationUser user = await userManager.FindByIdAsync(oauthSession.UserId);
//Uncomment this and the closing brace to verify the PIN hash referenced above
//if (userManager.PasswordHasher.VerifyHashedPassword(user.PINHash,submittedPin) == PasswordVerificationResult.Success)
//{
context.OwinContext.Set<ApplicationUser>(NicksApplicationOAuthProvider.OwinUserKey, user);
ClaimsIdentity oAuthIdentity = await user.GenerateUserIdentityAsync(userManager, OAuthDefaults.AuthenticationType);
IDictionary<string, string> properties = new Dictionary<string, string>{ { "userName", user.UserName } };
AuthenticationTicket ticket = new AuthenticationTicket(oAuthIdentity, new AuthenticationProperties(properties));
ticket.Properties.IssuedUtc = DateTimeOffset.UtcNow;
ticket.Properties.ExpiresUtc = DateTimeOffset.UtcNow.Add(Startup.OAuthOptions.AccessTokenExpireTimeSpan);
context.SetTicket(ticket);
//}
}
}
}
}
示例2: ReceiveAsync
public override async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
{
var url = string.Format(_tokenValidationEndpoint, context.Token);
var response = await _client.GetAsync(url);
if (response.StatusCode != HttpStatusCode.OK)
{
return;
}
var jsonString = await response.Content.ReadAsStringAsync();
var dictionary = JsonConvert.DeserializeObject<Dictionary<string, object>>(jsonString);
var claims = new List<Claim>();
foreach (var item in dictionary)
{
var values = item.Value as IEnumerable<object>;
if (values == null)
{
claims.Add(new Claim(item.Key, item.Value.ToString()));
}
else
{
foreach (var value in values)
{
claims.Add(new Claim(item.Key, value.ToString()));
}
}
}
context.SetTicket(new AuthenticationTicket(new ClaimsIdentity(claims, _authenticationType), new AuthenticationProperties()));
}
示例3: Receive
public void Receive(AuthenticationTokenReceiveContext context)
{
var oAuthIdentity = new ClaimsIdentity();
oAuthIdentity.AddClaim(new Claim(ClaimTypes.Name, "jeremy"));
var ticket = new AuthenticationTicket(oAuthIdentity, new AuthenticationProperties());
context.SetTicket(ticket);
}
示例4: ReceiveAsync
public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
{
TicketResult result = await RemoveAsync(context);
if (result.Deleted)
{
context.SetTicket(result.Ticket);
}
}
示例5: Receive
public void Receive(AuthenticationTokenReceiveContext context)
{
TicketResult result = Remove(context);
if (result.Deleted)
{
context.SetTicket(result.Ticket);
}
}
示例6: ReceiveAsync
public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
{
AuthenticationTicket ticket;
if (_refreshTokens.TryRemove(context.Token, out ticket))
{
context.SetTicket(ticket);
}
}
示例7: Receive
public void Receive(AuthenticationTokenReceiveContext context)
{
//TODO: before generating a new ticket, validate the ticket has not expired, and has never
//been used to generate a new ticket
var token = new CustomTokenFormat().Unprotect(context.Token.Replace(" ", "+"));
var ticket = AuthTicketBuilder.BuildTicket(token);
context.SetTicket(ticket);
}
示例8: Receive
public void Receive(AuthenticationTokenReceiveContext context)
{
AuthenticationTicket ticket;
if (RefreshTokens.TryRemove(context.Token, out ticket))
{
context.SetTicket(ticket);
}
}
示例9: ReceiveAsync
//<summary>
//验证Token
//</summary>
//<param name="context">上下文</param>
//<returns></returns>
public override async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
{
var request = new OAuthRequestTokenContext(context.OwinContext, context.Token);
var ticket = new AuthenticationTicket(new ClaimsIdentity(), new AuthenticationProperties()
{
IssuedUtc = DateTime.UtcNow.AddYears(-1),
ExpiresUtc = DateTime.UtcNow.AddYears(-1)
});
if (request == null || request.Token.IsNullOrEmpty())
{
context.SetTicket(ticket);
}
//验证Token是否过期
var vaild = true;//await _clientAuthorizationService.VaildOAuthClientSecretAsync();
if (vaild)
{
context.SetTicket(ticket);
}
}
示例10: ReceiveAsync
public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
{
AuthenticationTicket ticket;
string header = context.OwinContext.Request.Headers["Authorization"];
if (_refreshTokens.TryRemove(context.Token, out ticket))
{
context.SetTicket(ticket);
}
}
示例11: ReceiveAsync
public override Task ReceiveAsync(AuthenticationTokenReceiveContext context)
{
var tokenValidator = new TokenValidator();
ClaimsPrincipal principal = tokenValidator.Validate(context.Token, _options);
context.SetTicket(new AuthenticationTicket((ClaimsIdentity)principal.Identity,
new AuthenticationProperties()));
return base.ReceiveAsync(context);
}
示例12: ReceiveAsync
public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
{
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { "*" });
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Headers", new[] { "Content-Type" });
AuthenticationTicket ticket;
if (_refreshTokens.TryRemove(context.Token, out ticket))
{
context.SetTicket(ticket);
}
//return Task.FromResult<object>(null);
}
示例13: ReceiveAsync
public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
{
//var hashedTokenId = CryptoAes.GetHash(context.Token);
using (var authenticationTokenService = _dependencyResolver.GetService<IAuthenticationTokenFactory>())
{
var ticket = await authenticationTokenService.IssueAuthenticationTicketAsync(context.Token);
if (ticket != null)
{
context.SetTicket(ticket);
}
}
}
示例14: ReceiveAsync
public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
{
Guid token;
if (Guid.TryParse(context.Token, out token))
{
AuthenticationTicket ticket;
if (_refreshTokens.TryRemove(ComputeHash(token), out ticket))
{
context.SetTicket(ticket);
}
}
}
示例15: ReceiveAsync
public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
{
string clientId = context.OwinContext.Get<string>("as:client_id");
string ticket = refreshTokenService.GetAuthenticationTicket(new Guid(context.Token), clientId);
if (!string.IsNullOrEmpty(ticket) && !string.IsNullOrWhiteSpace(ticket))
{
context.SetTicket(serializer.Deserialize(System.Text.Encoding.Default.GetBytes(ticket)));
var command = new ReduceRefreshTokenTTL()
{
ClientId = clientId,
RefreshToken = Guid.Parse(context.Token),
AuthenticationTicket = ticket,
TTL = ttlChange
};
this.commandBus.Send(command);
}
}