private NuGetAuthenticationResult Authenticate(string apiKey) { // No authentication is necessary if there is no required API key. if (string.IsNullOrEmpty(_apiKey)) { return(NuGetAuthenticationResult.Success()); } if (string.IsNullOrEmpty(apiKey)) { return(NuGetAuthenticationResult.Fail("No Api Token provided.", "AvantiPoint Package Server")); } return(_apiKey == apiKey?NuGetAuthenticationResult.Success() : NuGetAuthenticationResult.Fail("Invalid Api Token provided.", "AvantiPoint Package Server")); }
private NuGetAuthenticationResult CreateResult(AuthToken token, bool includeRealm) { if (token is null || !token.IsValid()) { return(Fail("Invalid Token or Credentials", includeRealm)); } var identity = new ClaimsIdentity("GitHub Auth"); identity.AddClaim(new Claim(ClaimTypes.Name, token.User.Name)); identity.AddClaim(new Claim(ClaimTypes.Email, token.User.Email)); identity.AddClaim(new Claim(FeedClaims.Token, token.Key)); identity.AddClaim(new Claim(FeedClaims.TokenDescription, token.Description)); identity.AddClaim(new Claim(ClaimTypes.Role, FeedRoles.Consumer)); if (token.User.PackagePublisher) { identity.AddClaim(new Claim(ClaimTypes.Role, FeedRoles.Publisher)); } _logger.LogInformation($"Authenticated user: {token.User.Name} from {Connection.RemoteIpAddress}."); return(NuGetAuthenticationResult.Success(new ClaimsPrincipal(identity))); }
public Task <NuGetAuthenticationResult> AuthenticateAsync(string username, string token, CancellationToken cancellationToken) => Task.FromResult(NuGetAuthenticationResult.Success());
public Task <NuGetAuthenticationResult> AuthenticateAsync(string username, string token, CancellationToken cancellationToken) { var result = username == "skroob" && token == "12345" ? NuGetAuthenticationResult.Success(DemoUser) : NuGetAuthenticationResult.Fail("Invalid username or token", "Demo Authenticated Feed"); return(Task.FromResult(result)); }
public Task <NuGetAuthenticationResult> AuthenticateAsync(string apiKey, CancellationToken cancellationToken) { var result = apiKey == "12345" ? NuGetAuthenticationResult.Success(DemoUser) : NuGetAuthenticationResult.Fail("Unauthorized apiKey", "Demo Authenticated Feed"); return(Task.FromResult(result)); }