コード例 #1
0
        public ClientAuthenticationTests()
        {
            Scopes.Add(StandardScopes.OpenId);
            Clients.Add(new Client
            {
                Enabled       = true,
                ClientId      = "code_client",
                ClientSecrets = new List <Secret>
                {
                    new Secret("secret".Sha512())
                },

                Flow = Flows.AuthorizationCode,
                AllowAccessToAllScopes = true,

                RequireConsent = false,
                RedirectUris   = new List <string>
                {
                    "https://code_client/callback",
                    "https://code_client/callback?foo=bar&baz=quux"
                }
            });
            Users.Add(new InMemoryUser
            {
                Subject  = "bob",
                Username = "******",
                Claims   = new Claim[]
                {
                    new Claim("name", "Bob Loblaw"),
                    new Claim("email", "*****@*****.**"),
                    new Claim("role", "Attorney"),
                }
            });
        }
コード例 #2
0
ファイル: TestSink.cs プロジェクト: zinoviev/Mvc
 public void Begin(BeginScopeContext context)
 {
     if (BeginEnabled == null || BeginEnabled(context))
     {
         Scopes.Add(context);
     }
 }
コード例 #3
0
 /// <summary>
 /// Creates a new GoogleRealtimeDataCollector object using the Influx Database with the given name at the given endpoint to store the data using the given measurement name.
 /// </summary>
 /// <param name="databaseEndpoint">The address of an Influx Database endpoint. Usually defaults to http://localhost:8086.</param>
 /// <param name="databaseName">The name of the database the collector will save the data in.</param>
 /// <param name="measurementName">The measurement name that will be used when saving data in the database.</param>
 /// <param name="oAuthJSONPath">The location of the JSON file obtained from the Google Developer Console. It contains the data in order to authenticate against the Google OAuth 2.0 API.</param>
 /// <param name="userName">The user name of the Google account that is supposed to run the app.</param>
 public GoogleRealtimeDataCollector(string databaseEndpoint, string databaseName, string measurementName, string oAuthJSONPath, string userName) : base(databaseEndpoint, databaseName, measurementName, oAuthJSONPath, userName)
 {
     Scopes.Add("https://www.googleapis.com/auth/analytics.readonly");
     AnalyticsService      = Auth.GoogleAuthenticator_v3.AuthenticateByOAuth2(OAuthJSONPath, UserName, Scopes.ToArray());
     GetRequest            = AnalyticsService.Data.Realtime.Get("ga:148601695", "rt:pageviews");
     GetRequest.Dimensions = "rt:minutesAgo";
 }
コード例 #4
0
 internal void CopyFrom(FindCriteriaElement other)
 {
     foreach (ContractTypeNameElement ctn in other.ContractTypeNames)
     {
         ContractTypeNames.Add(new ContractTypeNameElement()
         {
             Name = ctn.Name, Namespace = ctn.Namespace
         });
     }
     Duration = other.Duration;
     foreach (XmlElementElement ext in other.Extensions)
     {
         Extensions.Add(new XmlElementElement()
         {
             XmlElement = (XmlElement)ext.XmlElement.CloneNode(true)
         });
     }
     MaxResults   = other.MaxResults;
     ScopeMatchBy = other.ScopeMatchBy;
     foreach (ScopeElement scope in other.Scopes)
     {
         Scopes.Add(new ScopeElement()
         {
             Scope = scope.Scope
         });
     }
 }
コード例 #5
0
        public virtual ApiResourceScope AddScope([NotNull] string scope)
        {
            var apiResourceScope = new ApiResourceScope(Id, scope);

            Scopes.Add(apiResourceScope);
            return(apiResourceScope);
        }
コード例 #6
0
        internal void InitializeFrom(FindCriteria fc)
        {
            foreach (var ctn in fc.ContractTypeNames)
            {
                ContractTypeNames.Add(new ContractTypeNameElement()
                {
                    Name = ctn.Name, Namespace = ctn.Namespace
                });
            }
            Duration = fc.Duration;
            var doc = new XmlDocument();

            foreach (var ext in fc.Extensions)
            {
                var xr = ext.CreateReader();
                xr.MoveToContent();
                Extensions.Add(new XmlElementElement()
                {
                    XmlElement = (XmlElement)doc.ReadNode(xr)
                });
            }
            MaxResults   = fc.MaxResults;
            ScopeMatchBy = fc.ScopeMatchBy;
            foreach (var scope in fc.Scopes)
            {
                Scopes.Add(new ScopeElement()
                {
                    Scope = scope
                });
            }
        }
コード例 #7
0
        /// <inheritdoc/>
        public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception?exception, Func <TState, Exception?, string> formatter)
        {
            if (!IsEnabled(logLevel))
            {
                return;
            }

            ICollection <object>?Scopes = null;
            LoggerGroup?         Group  = null;

            ScopeProvider?.ForEachScope(
                (scope, state) =>
            {
                if (scope is LoggerGroup LoggerGroup)
                {
                    if (Group == null || LoggerGroup.Priority >= Group.Priority)
                    {
                        Group = LoggerGroup;
                    }
                    return;
                }
                if (Scopes == null)
                {
                    Scopes = new Collection <object>();
                }
                Scopes.Add(scope);
            },
                state);

            _AddMessageAction(
                LoggerJsonMessage.FromLoggerData(Group?.GroupName, _CategoryName, Scopes, logLevel, eventId, state, exception, formatter));
        }
コード例 #8
0
        public Statement DecompileForEach(bool isDynArray = false)
        {
            PopByte();
            var scopeStatements = new List <Statement>();

            var iteratorFunc = DecompileExpression();

            if (iteratorFunc == null)
            {
                return(null);
            }

            if (isDynArray)
            {
                Expression dynArrVar   = DecompileExpression();
                bool       hasIndex    = Convert.ToBoolean(ReadByte());
                Expression dynArrIndex = DecompileExpression();
                iteratorFunc = new DynArrayIterator(iteratorFunc, dynArrVar, dynArrIndex);
            }

            var scopeEnd = ReadUInt16(); // MemOff

            ForEachScopes.Push(scopeEnd);

            Scopes.Add(scopeStatements);
            CurrentScope.Push(Scopes.Count - 1);
            while (Position < Size)
            {
                if (CurrentIs(OpCodes.IteratorNext))
                {
                    PopByte(); // IteratorNext
                    if (PeekByte == (byte)OpCodes.IteratorPop)
                    {
                        StatementLocations[(ushort)(Position - 1)] = new IteratorNext();
                        StatementLocations[(ushort)Position]       = new IteratorPop();
                        PopByte(); // IteratorPop
                        break;
                    }
                    Position--;
                }

                var current = DecompileStatement();
                if (current == null)
                {
                    return(null); // ERROR ?
                }
                scopeStatements.Add(current);
            }
            CurrentScope.Pop();
            ForEachScopes.Pop();

            var statement = new ForEachLoop(iteratorFunc, new CodeBody(scopeStatements))
            {
                iteratorPopPos = Position - 1
            };

            StatementLocations.Add(StartPositions.Pop(), statement);
            return(statement);
        }
コード例 #9
0
 public void AddScope(string scope)
 {
     _namedScopes[scope] = scope;
     if (!Scopes.Contains(scope))
     {
         Scopes.Add(scope);
     }
 }
コード例 #10
0
        public void AddScopes(string startIp, string endIp)
        {
            var scope = new Scope
            {
                Min = ToLong(startIp),
                Max = ToLong(endIp)
            };

            Scopes.Add(scope);
        }
コード例 #11
0
 public virtual void AddScope(
     [NotNull] string name,
     string displayName           = null,
     string description           = null,
     bool required                = false,
     bool emphasize               = false,
     bool showInDiscoveryDocument = true)
 {
     Scopes.Add(new ApiScope(Id, name, displayName, description, required, emphasize, showInDiscoveryDocument));
 }
コード例 #12
0
 public void AddScopes(List <string> scopes)
 {
     foreach (string scope in scopes)
     {
         _namedScopes[scope] = scope;
         if (!Scopes.Contains(scope))
         {
             Scopes.Add(scope);
         }
     }
 }
コード例 #13
0
 public LiveService(params string[] scopes)
 {
     Debug.Assert(Scopes != null);
     if (scopes != null && scopes.Length > 0)
     {
         foreach (string scope in scopes)
         {
             Scopes.Add(scope);
         }
     }
 }
コード例 #14
0
        public virtual ApiScopeDto AddScope(
            [NotNull] string name,
            string displayName           = null,
            string description           = null,
            bool required                = false,
            bool emphasize               = false,
            bool showInDiscoveryDocument = true)
        {
            var scope = new ApiScopeDto(Id, name, displayName, description, required, emphasize, showInDiscoveryDocument);

            Scopes.Add(scope);
            return(scope);
        }
コード例 #15
0
 public AuthToken(string name, string value, List <string> scopes = null)
 {
     Name   = name;
     _value = value;
     Scopes = scopes ?? new List <string>();
     if (Name == SessionToken)
     {
         if (Scopes.Count == 0)
         {
             Name = HttpFullAccess;
             Scopes.Add("html.*");
         }
     }
 }
コード例 #16
0
 public void AddScope(int scopeId)
 {
     if (Scopes.FirstOrDefault(s => s.ScopeId == scopeId) == null)
     {
         Scope s = new Scope(scopeId);
         if (s.ScopeId > 0)
         {
             Scopes.Add(s);
         }
         else
         {
             throw new ArgumentException("Scope not found.", "scopeId");
         }
     }
 }
コード例 #17
0
        public ApiResource(string name, string displayName, IEnumerable <string> claimTypes)
        {
            Name        = name;
            DisplayName = displayName;

            Scopes.Add(new Scope(name, displayName));

            if (claimTypes != null && claimTypes.Count() != 0)
            {
                foreach (var type in claimTypes)
                {
                    UserClaims.Add(type);
                }
            }
        }
コード例 #18
0
        // Get existing scope or add new one from symbol
        public Scope GetScope(string symbol)
        {
            var existing = Scopes.FirstOrDefault(x => x.Name
                                                 == Scope.ExtractScope(symbol));

            if (existing != null)
            {
                return(existing);
            }
            else
            {
                var newScope = Scope.ParseSymbol(this, symbol);
                Scopes.Add(newScope);
                return(newScope);
            }
        }
コード例 #19
0
            public void Log <TState>(LogLevel logLevel, EventId eventId, TState state, Exception?exception, Func <TState, Exception?, string> formatter)
            {
                ICollection <object>?Scopes = null;

                _ScopeProvider.ForEachScope(
                    (scope, state) =>
                {
                    if (Scopes == null)
                    {
                        Scopes = new Collection <object>();
                    }
                    Scopes.Add(scope);
                },
                    state);

                Message = LoggerJsonMessage.FromLoggerData(null, "Category", Scopes, logLevel, eventId, state, exception, formatter);
            }
コード例 #20
0
        public ApiResource(string scopeName, string displayName, IEnumerable <string> userClaimTypes)
        {
            if (scopeName.IsMissing())
            {
                throw new ArgumentNullException(nameof(scopeName));
            }

            Name = scopeName;
            Scopes.Add(new Scope(scopeName, displayName));

            if (!userClaimTypes.IsNullOrEmpty())
            {
                foreach (var type in userClaimTypes)
                {
                    UserClaims.Add(new UserClaim(type));
                }
            }
        }
コード例 #21
0
        public Task <IdentityServiceResult> AddScopeAsync(TApplication application, string scope, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            ThrowIfDisposed();
            if (application == null)
            {
                throw new ArgumentNullException(nameof(application));
            }

            if (scope == null)
            {
                throw new ArgumentNullException(nameof(scope));
            }

            Scopes.Add(CreateScope(application, scope));

            return(Task.FromResult(IdentityServiceResult.Success));
        }
コード例 #22
0
        public SwitchStatement DecompileSwitch()
        {
            PopByte();
            var    objIndex        = ReadObject();
            var    unknByte        = ReadByte();
            var    expr            = DecompileExpression();
            var    scopeStatements = new List <Statement>();
            UInt16 endOffset       = 0xFFFF; // set it at max to begin with, so we can begin looping

            Scopes.Add(scopeStatements);
            CurrentScope.Push(Scopes.Count - 1);
            while (Position < endOffset && Position < Size)
            {
                if (CurrentIs(StandardByteCodes.Jump)) // break detected, save the endOffset
                {                                      // executes for all occurences, to handle them all.
                    StartPositions.Push((UInt16)Position);
                    PopByte();
                    endOffset = ReadUInt16();
                    var breakStatement = new BreakStatement(null, null);
                    StatementLocations.Add(StartPositions.Pop(), breakStatement);
                    scopeStatements.Add(breakStatement);
                    continue;
                }

                var current = DecompileStatement();
                if (current == null)
                {
                    return(null); // ERROR ?
                }
                scopeStatements.Add(current);
                if (current is DefaultStatement && endOffset == 0xFFFF)
                {
                    break; // If no break was detected, we end the switch rather than include the rest of ALL code in the default.
                }
            }
            CurrentScope.Pop();

            var statement = new SwitchStatement(expr, new CodeBody(scopeStatements, null, null), null, null);

            StatementLocations.Add(StartPositions.Pop(), statement);
            return(statement);
        }
コード例 #23
0
        /// <summary>
        /// 初始化<see cref="ApiResource"/>
        /// </summary>
        /// <param name="name">名称</param>
        /// <param name="displayName">显示名称</param>
        /// <param name="claimTypes">声明类型</param>
        public ApiResource(string name, string displayName, IList <string> claimTypes)
        {
            if (name.IsNull())
            {
                throw new ArgumentNullException(nameof(name));
            }

            Name        = name;
            DisplayName = displayName;

            Scopes.Add(new ApiScope(name, displayName));

            if (claimTypes != null && !claimTypes.Any())
            {
                foreach (var type in claimTypes)
                {
                    this.SetUserClaims(s => s.SetValue(type));
                }
            }
        }
コード例 #24
0
ファイル: Authorization.cs プロジェクト: Jeinhaus/TwitchLib
        /// <summary>Constructor for Authorization object.</summary>
        /// <param name="json"></param>
        public Authorization(JToken json)
        {
            if (json.SelectToken("scopes") != null)
            {
                foreach (JToken scope in json.SelectToken("scopes"))
                {
                    Scopes.Add(scope.ToString());
                }
            }

            if (json.SelectToken("created_at") != null)
            {
                CreatedAt = Common.Helpers.DateTimeStringToObject(json.SelectToken("created_at").ToString());
            }

            if (json.SelectToken("updated_at") != null)
            {
                UpdatedAt = Common.Helpers.DateTimeStringToObject(json.SelectToken("updated_at").ToString());
            }
        }
コード例 #25
0
        public OAuth2ResourceProvider AddRequestScope <TRequest>()
            where TRequest : OAuthRequest, new()
        {
            var request = new TRequest();

            foreach (var scope in request.RequiredScopes)
            {
                if (!AvailableScopes.Contains(scope))
                {
                    throw new InvalidScopeException(string.Format(
                                                        StringResources.ScopeException,
                                                        scope,
                                                        this.GetType().Name));
                }
                if (!Scopes.Contains(scope))
                {
                    Scopes.Add(scope);
                }
            }

            return(this);
        }
コード例 #26
0
        public Statement DecompileConditionalJump(bool isOpt = false) // TODO: guess for loop, probably requires a large restructure
        {
            PopByte();
            var       scopeStartOffset = StartPositions.Pop();
            Statement statement        = null;
            bool      hasElse          = false;
            var       scopeStatements  = new List <Statement>();

            UInt16     scopeEndJmpOffset = 0;
            UInt16     afterScopeOffset  = 0;
            Expression conditional       = null;

            if (isOpt)
            {
                var obj      = ReadObject();
                var optCheck = Convert.ToBoolean(ReadByte());
                afterScopeOffset = ReadUInt16();

                String special = (optCheck ? "" : "!") + obj.ObjectName;
                conditional = new SymbolReference(null, null, null, special);
            }
            else
            {
                afterScopeOffset = ReadUInt16();
                conditional      = DecompileExpression();
            }

            if (conditional == null)
            {
                return(null);
            }

            if (afterScopeOffset < scopeStartOffset) // end of do_until detection
            {
                scopeStartOffset = afterScopeOffset;
                var outerScope     = Scopes[CurrentScope.Peek()];
                var startStatement = StatementLocations[afterScopeOffset];
                StatementLocations.Remove(afterScopeOffset);
                var index = outerScope.IndexOf(startStatement);
                scopeStatements = new List <Statement>(outerScope.Skip(index));
                outerScope.RemoveRange(index, outerScope.Count - index);
                statement = new DoUntilLoop(conditional, new CodeBody(scopeStatements, null, null), null, null);
            }

            Scopes.Add(scopeStatements);
            CurrentScope.Push(Scopes.Count - 1);
            while (Position < afterScopeOffset)
            {
                if (CurrentIs(StandardByteCodes.Jump))
                {
                    var contPos = (UInt16)Position;
                    PopByte();
                    scopeEndJmpOffset = ReadUInt16();
                    if (scopeEndJmpOffset == scopeStartOffset)
                    {
                        statement = new WhileLoop(conditional, new CodeBody(scopeStatements, null, null), null, null);
                        break;
                    }
                    else if (Position < afterScopeOffset) // if we are not at the end of the scope, this is a continue statement in a loop rather than an else statement
                    {
                        var cont = new ContinueStatement(null, null);
                        StatementLocations.Add(contPos, cont);
                        scopeStatements.Add(cont);
                    }
                    else if (ForEachScopes.Count != 0 && scopeEndJmpOffset == ForEachScopes.Peek())
                    {
                        var breakStatement = new BreakStatement(null, null);
                        StatementLocations.Add(contPos, breakStatement);
                        scopeStatements.Add(breakStatement);
                    }
                    else
                    {
                        hasElse = true;
                    }

                    continue;
                }

                var current = DecompileStatement();
                if (current == null)
                {
                    return(null); // ERROR ?
                }
                scopeStatements.Add(current);
            }
            CurrentScope.Pop();


            List <Statement> elseStatements = new List <Statement>();

            if (hasElse)
            {
                var endElseOffset = scopeEndJmpOffset;
                Scopes.Add(elseStatements);
                CurrentScope.Push(Scopes.Count - 1);
                while (Position < endElseOffset)
                {
                    var current = DecompileStatement();
                    if (current == null)
                    {
                        return(null); // ERROR ?
                    }
                    elseStatements.Add(current);
                }
                CurrentScope.Pop();
            }

            statement = statement ?? new IfStatement(conditional, new CodeBody(scopeStatements, null, null),
                                                     null, null, elseStatements.Count != 0 ? new CodeBody(elseStatements, null, null) : null);
            StatementLocations.Add(scopeStartOffset, statement);
            return(statement);
        }
コード例 #27
0
 public IDisposable BeginScope <TState>(TState state)
 {
     Scopes.Add(state?.ToString());
     return(null);
 }
コード例 #28
0
 public DebugVariableLinkCollection()
 {
     Scopes.Add(_variablesScope);
     Scopes.Add(_rawScope);
 }
コード例 #29
0
        public Statement DecompileForEach(bool isDynArray = false) // TODO: guess for loop, probably requires a large restructure
        {
            PopByte();
            var scopeStatements = new List <Statement>();

            var iteratorFunc = DecompileExpression();

            if (iteratorFunc == null)
            {
                return(null);
            }

            Expression dynArrVar   = null;
            Expression dynArrIndex = null;
            bool       unknByte    = false;

            if (isDynArray)
            {
                dynArrVar   = DecompileExpression();
                unknByte    = Convert.ToBoolean(ReadByte());
                dynArrIndex = DecompileExpression();
            }

            var scopeEnd = ReadUInt16(); // MemOff

            ForEachScopes.Push(scopeEnd);

            Scopes.Add(scopeStatements);
            CurrentScope.Push(Scopes.Count - 1);
            while (Position < Size)
            {
                if (CurrentIs(StandardByteCodes.IteratorNext) && PeekByte == (byte)StandardByteCodes.IteratorPop)
                {
                    PopByte(); // IteratorNext
                    PopByte(); // IteratorPop
                    break;
                }

                var current = DecompileStatement();
                if (current == null)
                {
                    return(null); // ERROR ?
                }
                scopeStatements.Add(current);
            }
            CurrentScope.Pop();
            ForEachScopes.Pop();

            if (isDynArray)
            {
                var builder = new CodeBuilderVisitor(); // what a wonderful hack, TODO.
                iteratorFunc.AcceptVisitor(builder);
                var arrayName  = new SymbolReference(null, null, null, builder.GetCodeString());
                var parameters = new List <Expression>()
                {
                    dynArrVar, dynArrIndex
                };
                iteratorFunc = new FunctionCall(arrayName, parameters, null, null);
            }

            var statement = new ForEachLoop(iteratorFunc, new CodeBody(scopeStatements, null, null), null, null);

            StatementLocations.Add(StartPositions.Pop(), statement);
            return(statement);
        }
コード例 #30
0
 public IDisposable BeginScope <TState>(TState state)
 {
     Scopes.Add(state);
     return(new Scope());
 }