Best NBi code snippet using NBi.Core.Api.Authentication.ApiKey
RestHelper.cs
Source:RestHelper.cs
...53 var helper = new ScalarHelper(ServiceLocator, Settings, Scope, new Context(Variables));54 switch (authentication.Protocol)55 {56 case AnonymousXml _: return new Anonymous();57 case ApiKeyXml x: return new ApiKey(helper.InstantiateResolver<string>(x.Name), helper.InstantiateResolver<string>(x.Value));58 case HttpBasicXml x: return new HttpBasic(helper.InstantiateResolver<string>(x.Username), helper.InstantiateResolver<string>(x.Password));59 case NtmlCurrentUserXml _: return new NtlmCurrentUser();60 case NtmlUserPasswordXml x: return new NtlmUserPassword(helper.InstantiateResolver<string>(x.Username), helper.InstantiateResolver<string>(x.Password));61 case OAuth2Xml x: return new OAuth2(helper.InstantiateResolver<string>(x.AccessToken), helper.InstantiateResolver<string>(x.TokenType));62 default: throw new ArgumentOutOfRangeException();63 }64 }65 }66}...
ApiKey.cs
Source:ApiKey.cs
...8using System.Threading.Tasks;9using NBi.Extensibility.Resolving;10namespace NBi.Core.Api.Authentication11{12 public class ApiKey : IAuthentication13 {14 public IScalarResolver<string> Name { get; }15 public IScalarResolver<string> Value { get; }16 public ApiKey(IScalarResolver<string> name, IScalarResolver<string> value)17 => (Name, Value) = (name, value);18 public ApiKey(IScalarResolver<string> value)19 : this(new LiteralScalarResolver<string>("apiKey"), value) { }20 public IAuthenticator GetAuthenticator() => new ApiKeyAuthenticator(Name.Execute(), Value.Execute());21 public class ApiKeyAuthenticator : IAuthenticator22 {23 public string Name { get; }24 public string Value { get; }25 public ApiKeyAuthenticator(string name, string value)26 => (Name, Value) = (name, value);27 public void Authenticate(IRestClient client, IRestRequest request)28 {29 request.AddHeader(Name, Value);30 }31 }32 }33}...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!