private async Task <ExternalUserDto> GetUserInfo(string accessToken, IProviderOptions options) { var userInfoClient = new UserInfoClient(options.UserInfoEndpoint); var userInfo = await userInfoClient.GetAsync(accessToken); return(!userInfo.IsError ? CreateExternalUserFromClaims(userInfo.Claims.ToList(), options.LoginProvider) : null); }
static void ResolveOptionsReferences( IEnumerable <UnresolvedOptions> unresolved_options_references, IDictionary <string, IProviderOptions> reference_table) { foreach ( UnresolvedOptions unresolved_options in unresolved_options_references) { IProviderOptions options = unresolved_options.options; IList <string> references = unresolved_options.references; foreach (string reference in references) { IProviderOptions referenced_options; if (reference_table.TryGetValue(reference, out referenced_options)) { foreach ( KeyValuePair <string, string> referenced_option in referenced_options) { options[referenced_option.Key] = referenced_option.Value; } } else { throw new ConfigurationException( string.Format( Resources.Resources.Configuration_providers_unresolved_reference, reference)); } } } }
public static ReplicaNode Parse(XmlElement element) { string name = GetAttributeValue(element, Strings.kNameAttribute); IProviderOptions options = GetOptions(name, element); return(new ReplicaNode(name, options)); }
/// <summary> /// Create a set of options for the C# or VB CodeProviders using the specified inputs. /// </summary> public ProviderOptions(IProviderOptions opts) { this.CompilerFullPath = opts.CompilerFullPath; this.CompilerServerTimeToLive = opts.CompilerServerTimeToLive; this.CompilerVersion = opts.CompilerVersion; this.WarnAsError = opts.WarnAsError; this.UseAspNetSettings = opts.UseAspNetSettings; this.AllOptions = new Dictionary <string, string>(opts.AllOptions); }
private async Task <JwksKey> GetJwksInfo(string kid, IProviderOptions options) { using (var httpClient = new HttpClient()) { var response = await httpClient.GetAsync(options.JwksUrl); var json = await response.Content.ReadAsStringAsync(); var data = JsonConvert.DeserializeObject <JwksData>(json); return(data.Keys.FirstOrDefault(x => x.Kid == kid) ?? data.Keys.FirstOrDefault()); } }
private async Task <RSAParameters> CreateRsaParameters(string kid, IProviderOptions options) { var key = await GetJwksInfo(kid, options); var keyExponent = GetKeyInBase64Format(key.KeyExponent); var keyModules = GetKeyInBase64Format(key.KeyModules); return(new RSAParameters { Modulus = Convert.FromBase64String(keyModules), Exponent = Convert.FromBase64String(keyExponent) }); }
public void DefaultSettings() { IProviderOptions opts = CompilationUtil.GetProviderOptionsFor(".fakevb"); Assert.IsNotNull(opts); Assert.AreEqual <string>(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, @"bin\roslyn"), opts.CompilerFullPath); // Would include csc.exe or vbc.exe if the extension we searched for wasn't fake. Assert.AreEqual <int>(IsDev ? 15 * 60 : 10, opts.CompilerServerTimeToLive); // 10 in Production. 900 in a "dev" environment. Assert.IsTrue(opts.UseAspNetSettings); // Default is false... except through the GetProviderOptionsFor factory method we used here. Assert.IsFalse(opts.WarnAsError); Assert.IsNull(opts.CompilerVersion); Assert.AreEqual <int>(2, opts.AllOptions.Count); Assert.AreEqual <string>("foo2", opts.AllOptions["CustomSetting"]); Assert.AreEqual <string>("bar2", opts.AllOptions["AnotherCoolSetting"]); }
public void FromProviderOptions() { IProviderOptions opts = CompilationUtil.GetProviderOptionsFor(".fakecs"); Assert.IsNotNull(opts); Assert.AreEqual <string>(@"C:\Path\To\Nowhere\csc.exe", opts.CompilerFullPath); Assert.AreEqual <int>(42, opts.CompilerServerTimeToLive); Assert.IsFalse(opts.UseAspNetSettings); Assert.IsTrue(opts.WarnAsError); Assert.AreEqual <string>("v6.0", opts.CompilerVersion); Assert.AreEqual <int>(7, opts.AllOptions.Count); Assert.AreEqual <string>("foo", opts.AllOptions["CustomSetting"]); Assert.AreEqual <string>("bar", opts.AllOptions["AnotherCoolSetting"]); }
/// <summary> /// Initializes a new instance of the <see cref="ProviderNode"/> class by /// using the specified provider name, type and assembly location. /// </summary> /// <param name="name"> /// A string that uniquely identifies a provider within an collection. /// </param> /// <param name="type"> /// The provider's assembly-qualified name. /// </param> /// <param name="location"> /// The path to the directory where the provider assembly file is stored. /// </param> protected ProviderNode(string name, string type, string location) : base(name) { #if DEBUG if (type == null || location == null) { throw new ArgumentNullException(type == null ? "type" : "location"); } #endif type_ = type; location_ = location; group_ = string.Empty; options_ = new ProviderOptionsNode(name); aliases_ = new string[0]; }
private TokenValidationParameters CreateTokenValidatorParameters(RSA rsa, IProviderOptions options) { var parameters = new TokenValidationParameters { RequireExpirationTime = true, RequireSignedTokens = true, ValidateLifetime = true, IssuerSigningKey = new RsaSecurityKey(rsa), ValidateAudience = false, ValidateIssuer = true, ValidIssuer = options.ValidIssuer }; return(parameters); }
// <appSettings> override <providerOptions> for location only // Actually, we can't do this because A) AppSettings can be added but not cleaned up after this test, and // B) the setting has probably already been read and cached by the AppSettings utility class, so updating // the value here wouldn't have any affect anyway. //[TestMethod] public void FromAppSettings() { ConfigurationManager.AppSettings.Set("aspnet:RoslynCompilerLocation", @"C:\Location\for\all\from\appSettings\compiler.exe"); IProviderOptions opts = CompilationUtil.GetProviderOptionsFor(".fakecs"); ConfigurationManager.AppSettings.Remove("aspnet:RoslynCompilerLocation"); Assert.IsNotNull(opts); Assert.AreEqual <string>(@"C:\Location\for\all\from\appSettings\compiler.exe", opts.CompilerFullPath); Assert.AreEqual <int>(42, opts.CompilerServerTimeToLive); Assert.IsFalse(opts.UseAspNetSettings); Assert.IsTrue(opts.WarnAsError); Assert.AreEqual <string>("v6.0", opts.CompilerVersion); Assert.AreEqual <int>(7, opts.AllOptions.Count); Assert.AreEqual <string>("foo", opts.AllOptions["CustomSetting"]); Assert.AreEqual <string>("bar", opts.AllOptions["AnotherCoolSetting"]); }
private RedirectUrlDto GetAuthorizeUrl(IPAddress ip, IProviderOptions providerOptions) { var request = new AuthorizeRequest(providerOptions.AuthorizeEndpoint); var state = SaveState(ip); var url = request.CreateAuthorizeUrl( clientId: providerOptions.ClientId, responseType: providerOptions.ResponseType, scope: providerOptions.Scope, redirectUri: providerOptions.RedirectUrl, state: state); return(new RedirectUrlDto { Url = url }); }
public void FromEnvironment() { // See note on the 'FromAppSettings' test. //ConfigurationManager.AppSettings.Set("aspnet:RoslynCompilerLocation", @"C:\Location\for\all\from\appSettings\compiler.exe"); Environment.SetEnvironmentVariable("ROSLYN_COMPILER_LOCATION", @"C:\My\Compiler\Location\vbcsc.exe"); Environment.SetEnvironmentVariable("VBCSCOMPILER_TTL", "98"); IProviderOptions opts = CompilationUtil.GetProviderOptionsFor(".fakecs"); Environment.SetEnvironmentVariable("ROSLYN_COMPILER_LOCATION", null); Environment.SetEnvironmentVariable("VBCSCOMPILER_TTL", null); //ConfigurationManager.AppSettings.Remove("aspnet:RoslynCompilerLocation"); Assert.IsNotNull(opts); Assert.AreEqual <string>(@"C:\My\Compiler\Location\vbcsc.exe", opts.CompilerFullPath); Assert.AreEqual <int>(98, opts.CompilerServerTimeToLive); Assert.IsFalse(opts.UseAspNetSettings); Assert.IsTrue(opts.WarnAsError); Assert.AreEqual <string>("v6.0", opts.CompilerVersion); Assert.AreEqual <int>(7, opts.AllOptions.Count); Assert.AreEqual <string>("foo", opts.AllOptions["CustomSetting"]); Assert.AreEqual <string>("bar", opts.AllOptions["AnotherCoolSetting"]); }
static IProviderOptions GetOptions(string name, XmlElement element) { IList <string> options_references = new List <string>(); foreach (XmlNode node in element.ChildNodes) { if (node.NodeType == XmlNodeType.Element && Strings.AreEquals(node.Name, Strings.kOptionsNodeName)) { IProviderOptions options = ProviderOptionsNode .Parse(name, (XmlElement)node, out options_references); // replicas could nt have referential options. if (options_references.Count != 0) { throw new ConfigurationException( Resources.Resources. Configuration_providers_replicas_with_ref_options); } return(options); } } return(new ProviderOptionsNode(name)); }
private async Task <bool> ValidateOpenIdToken(TokenResponse tokenResponse, string state, IPAddress ip, IProviderOptions options) { if (tokenResponse.IsError || !state.Equals(_cacheService.GetStateOpenId(ip), StringComparison.OrdinalIgnoreCase)) { return(false); } var rsa = new RSACryptoServiceProvider(); var handler = new JwtSecurityTokenHandler(); var jsonToken = handler.ReadToken(tokenResponse.IdentityToken) as JwtSecurityToken; rsa.ImportParameters(await CreateRsaParameters(jsonToken?.Header.Kid, options)); var parameters = CreateTokenValidatorParameters(rsa, options); try { handler.ValidateToken( tokenResponse.IdentityToken, parameters, out _); return(true); } catch (Exception) { return(false); } }
public CSharpCompiler(CodeDomProvider codeDomProvider, IProviderOptions providerOptions = null) : base(codeDomProvider, providerOptions) { }
public Compiler(CodeDomProvider codeDomProvider, IProviderOptions providerOptions) { this._codeDomProvider = codeDomProvider; this._providerOptions = providerOptions; }
/// <summary> /// Creates an instance using the given ICompilerSettings /// </summary> /// <param name="providerOptions"></param> public VBCodeProvider(IProviderOptions providerOptions = null) { _providerOptions = providerOptions == null ? CompilationUtil.VBC2 : providerOptions; }
/// <summary> /// Creates an instance using the given IProviderOptions /// </summary> /// <param name="providerOptions"></param> public CSharpCodeProvider(IProviderOptions providerOptions = null) { _providerOptions = providerOptions == null ? CompilationUtil.CSC2 : providerOptions; }
ReplicaNode(string name, IProviderOptions options):base(name) { options_ = options; }
public VBCodeProvider(ICompilerSettings compilerSettings = null) { _providerOptions = compilerSettings == null ? CompilationUtil.VBC2 : new ProviderOptions(compilerSettings); }
ReplicaNode(string name, IProviderOptions options) : base(name) { options_ = options; }
public UnresolvedOptions(IProviderOptions options, IList<string> references) { this.options = options; this.references = references; }
public UnresolvedOptions(IProviderOptions options, IList <string> references) { this.options = options; this.references = references; }