本文整理汇总了C#中Microsoft.Owin.Security.Infrastructure.AuthenticationTokenReceiveContext类的典型用法代码示例。如果您正苦于以下问题:C# AuthenticationTokenReceiveContext类的具体用法?C# AuthenticationTokenReceiveContext怎么用?C# AuthenticationTokenReceiveContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AuthenticationTokenReceiveContext类属于Microsoft.Owin.Security.Infrastructure命名空间,在下文中一共展示了AuthenticationTokenReceiveContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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()));
}
示例2: ReceiveAsync
public Task ReceiveAsync(AuthenticationTokenReceiveContext context)
{
return Task.Run(() =>
{
Receive(context);
});
}
示例3: ReceiveAsync
public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
{
try
{
var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin") ?? "*";
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });
var hashedTokenId = Helper.GetHash(context.Token);
using (IRepository rep = new ApplicationRepository())
{
var refreshToken = await rep.RefreshTokens.FindAsync(hashedTokenId);
if (refreshToken != null)
{
//Get protectedTicket from refreshToken class
context.DeserializeTicket(refreshToken.ProtectedTicket);
var result = await rep.RefreshTokens.RemoveAsync(hashedTokenId);
}
}
}
catch (Exception e)
{
throw e;
}
}
示例4: ReceiveAsync
public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
{
try
{
var hashedTokenId = HashHelper.GetHash(context.Token);
using (AuthRepository authService = new AuthRepository())
{
var refreshToken = authService.FindRefreshToken(hashedTokenId);
if (refreshToken != null)
{
//Get protectedTicket from refreshToken class
context.DeserializeTicket(refreshToken.ProtectedTicket);
//remove token from db
var result = authService.RemoveRefreshToken(hashedTokenId);
}
}
}
catch (Exception ex)
{
Logger.Error("Error receiving token: " + ex.InnerException);
}
}
示例5: ReceiveAsync
public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
{
var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin");
if (context.OwinContext.Response.Headers.Keys.Contains("Access-Control-Allow-Origin"))
{
context.OwinContext.Response.Headers["Access-Control-Allow-Origin"] = allowedOrigin;
}
else
{
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] {allowedOrigin});
}
var hashedTokenId = TokenHelper.GetHash(context.Token);
using (var _repo = new AuthRepository())
{
var refreshToken = await _repo.FindRefreshToken(hashedTokenId);
if (refreshToken != null)
{
//Get protectedTicket from refreshToken class
context.DeserializeTicket(refreshToken.ProtectedTicket);
var result = await _repo.RemoveRefreshToken(hashedTokenId);
}
}
}
示例6: 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);
//}
}
}
}
}
示例7: ReceiveAsync
public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
{
// define o cabecalho da resposta do contexto do Owin com a permição de origem
var allowedOrigin = context.OwinContext.Get<string>("as:clientAllowedOrigin");
context.OwinContext.Response.Headers.Add("Access-Control-Allow-Origin", new[] { allowedOrigin });
// pega o Id do token pelo na requisição
var hashedTokenId = HashHelper.GetHash(context.Token);
// Identifica o Browser
var userAgent = HttpContext.Current.Request.UserAgent;
var userBrowser = new HttpBrowserCapabilities { Capabilities = new Hashtable { { string.Empty, userAgent } } };
var factory = new BrowserCapabilitiesFactory();
factory.ConfigureBrowserCapabilities(new NameValueCollection(), userBrowser);
var browser = userBrowser.Browser;
var refreshTokenDomain = DependecyConfig.Container.GetInstance<IRefreshTokenDomain>();
// busca o token na base de dados pelo id
var refreshToken = await refreshTokenDomain.ReadAsync(hashedTokenId, browser);
// se o token for encontrado
if (refreshToken != null)
{
// pega os dados do ticket para deserializar e gerar um novo ticket com
// as informações mapeadas do usuário que utiliza este token
var ticketSerializer = new TicketSerializer();
var ticket = ticketSerializer.Deserialize(refreshToken.ProtectedTicket);
context.SetTicket(ticket);
// remove o token da base de dados pois em nossa lógica, permitimos apenas
// um RefreshToken por usuário e aplicação cliente
await refreshTokenDomain.DeleteAsync(hashedTokenId, browser);
}
}
示例8: ReceiveAsync
public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
{
using (var ctx = new ApplicationDbContext())
{
// Get the hash of our token
var hash = Encryption.Hash(context.Token);
// Find the refresh token by its hash
var rt = (from r in ctx.RefreshTokens
where r.Id == hash
select r).SingleOrDefault();
if (rt != null)
{
// Get ticket from stored data
context.DeserializeTicket(rt.Ticket);
// Delete the token from the DB
ctx.RefreshTokens.Remove(rt);
// Save changes
await ctx.SaveChangesAsync();
}
}
}
示例9: 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);
}
示例10: Receive
/// <summary>
///
/// </summary>
/// <param name="context"></param>
public override void Receive(AuthenticationTokenReceiveContext context)
{
string token;
if (_refreshTokens.TryRemove(context.Token, out token))
{
context.DeserializeTicket(token);
}
}
示例11: Receive
public void Receive(AuthenticationTokenReceiveContext context)
{
TicketResult result = Remove(context);
if (result.Deleted)
{
context.SetTicket(result.Ticket);
}
}
示例12: ReceiveAsync
public async Task ReceiveAsync(AuthenticationTokenReceiveContext context)
{
TicketResult result = await RemoveAsync(context);
if (result.Deleted)
{
context.SetTicket(result.Ticket);
}
}
示例13: Receive
public override void Receive(AuthenticationTokenReceiveContext context)
{
string value;
if (_codes.TryRemove(context.Token, out value))
{
context.DeserializeTicket(value);
}
}
示例14: ReceiveAuthenticationCode
private void ReceiveAuthenticationCode(AuthenticationTokenReceiveContext context)
{
string value;
if (_authCodes.TryRemove(context.Token, out value))
{
context.DeserializeTicket(value);
}
}
示例15: Receive
public void Receive(AuthenticationTokenReceiveContext context)
{
AuthenticationTicket ticket;
if (RefreshTokens.TryRemove(context.Token, out ticket))
{
context.SetTicket(ticket);
}
}