private string GetSecurityToken()
        {
            var token = new TokenFactory(endpointUri, accessKey, accessKeyName)
                .Create(TokenType.SharedAccessSignature);

            return token;
        }
Esempio n. 2
0
 private void Add(TokenFactory factory, double weight)
 {
     Node node = new Node();
     if (sums.Count == 0) {
         node.sum = weight;
     } else {
         node.sum = sums[sums.Count - 1].sum + weight;
     }
     node.factory = factory;
     sums.Add(node);
 }
        public void Can_Generate_JWT_Token()
        {
            // Arrange
            var contract = Utilities.SetBasicJWTContract(_testInstance.X509Certificate);

            // Act
            var factory = new TokenFactory(_testInstance.IdentityConfigurationForTest);
            var token = factory.GenerateToken<JwtSecurityToken>(contract);

            // Assert
            Assert.IsNotNull(token, "Token came back empty");
            Assert.IsTrue(token.Audience.Equals(TestClaims.Audience));
            Assert.AreSame(token.Issuer, contract.Issuer, "Issuer incorrect");
            Assert.IsTrue(token.Header.Any(h => h.Key.Equals("typ") && h.Value.Equals("JWT")), "Invalid type");
            Assert.IsTrue(token.Header.Any(h => h.Key.Equals("alg") && h.Value.Equals("RS256")), "Invalid algorithm");
            Assert.IsTrue(
                token.Claims.Any(
                    c => c.Type.Equals(XspaClaimTypes.SubjectIdentifier) && c.Value.Equals(TestClaims.SubjectClaim)),
                "Subject Identifier incorrect");
            Assert.IsTrue(
                token.Claims.Any(
                    c =>
                        c.Type.Equals(XspaClaimTypes.OrganizationIdentifier) &&
                        c.Value.Equals(TestClaims.OrganizationIdClaim.ToString())),
                "Organization Identifier incorrect");
            Assert.IsTrue(
                token.Claims.Any(
                    c =>
                        c.Type.Equals(XspaClaimTypes.SubjectOrganization) &&
                        c.Value.Equals(TestClaims.OrganizationClaim)), "Subject Organization incorrect");
            Assert.IsTrue(
                token.Claims.Any(
                    c => c.Type.Equals(XspaClaimTypes.SubjectRole) && c.Value.Equals(TestClaims.SubjectRoleClaim.Code)),
                "Subject Role incorrect");
            Assert.IsTrue(
                token.Claims.Any(
                    c => c.Type.Equals(XspaClaimTypes.PurposeOfUse) && c.Value.Equals(TestClaims.PurposeOfUseClaim.Code)),
                "Purpose of Use incorrect");
            Assert.IsTrue(
                token.Claims.Any(
                    c => c.Type.Equals(XspaClaimTypes.NationalProviderIdentifier) && c.Value.Equals(TestClaims.NPIClaim)),
                "Npi incorrect");
            Assert.IsTrue(token.Expiration.HasValue, "Expiration is null");
            Assert.IsNotNull(token.Expiration);
            Assert.AreEqual(_testInstance.ValidExpiration.ToShortDateString(),
                Utilities.UnixTimeStampToDateTime(token.Expiration.Value).ToShortDateString());
            Assert.AreEqual(_testInstance.ValidExpiration.ToShortTimeString(),
                Utilities.UnixTimeStampToDateTime(token.Expiration.Value).ToShortTimeString());
            Assert.AreNotSame(_testInstance.ValidExpiration, Utilities.UnixTimeStampToDateTime(token.Expiration.Value));
        }
        public async Task TestMethod1()
        {
            const string apiHost = "https://api.github.com";
            const string appName = "githubvsintegrations";
            var tokenFactory = new TokenFactory(apiHost, appName);
            var token = await tokenFactory.CreateAuthorization(
                TokensEtc.UserName, TokensEtc.Password, new[] {"public_repo"});
            token.IsNotNull();

            // API 一個呼べればトークン取得は正しいだろう
            var github = new Github(token, "githubvsintegrations", apiHost);
            var cancellationToken = new CancellationToken();
            var repos = await github.ListUserRepository(cancellationToken);
            repos.IsNotNull();
            repos = await github.ListUserRepository(cancellationToken);
            repos.IsNotNull();
        }
Esempio n. 5
0
 public ReadMarksApi(HttpClient httpClient, TokenFactory tokenFactory, JsonSerializerOptions serializerOptions)
     : base(httpClient, tokenFactory, serializerOptions)
 {
 }
Esempio n. 6
0
 public myEurSwapRate11YOIS()
     : base(PricingDate_: DateTime.Today, Frequency_: Frequency.Annual, Period_: new Period(11, TimeUnit.Years), argDBID_: TokenFactory.New(Bloomberg: "EUSWE11 Curncy"), ForwardStart_: new Period(2, TimeUnit.Days), SwapFixedLegBDC_: BusinessDayConvention.ModifiedFollowing, SwapFixedLegDayCounter_: new Thirty360(), SwapFloatingLegIndex_: new Eonia())
 {
 }
Esempio n. 7
0
        private static async Task Main()
        {
            Console.Write("Enter App ID: ");

            var appId = Console.ReadLine();

            Console.Write("Enter App Secret: ");

            var appSecret = Console.ReadLine();

            Console.Write("Enter App Redirect URL: ");

            var redirectUrl = Console.ReadLine();

            _app = new App(appId, appSecret, redirectUrl);

            Console.Write("Enter Connection Mode (Live or Demo): ");

            var modeString = Console.ReadLine();

            var mode = (Mode)Enum.Parse(typeof(Mode), modeString, true);

            Console.Write("Enter Scope (Trading or Accounts): ");

            var scopeString = Console.ReadLine();

            var scope = (Scope)Enum.Parse(typeof(Scope), scopeString, true);

            var authUri = _app.GetAuthUri();

            System.Diagnostics.Process.Start("explorer.exe", $"\"{authUri}\"");

            ShowDashLine();

            Console.WriteLine("Follow the authentication steps on your browser, then copy the authentication code from redirect" +
                              " URL and paste it here.");

            Console.WriteLine("The authentication code is at the end of redirect URL and it starts after '?code=' parameter.");

            ShowDashLine();

            Console.Write("Enter Authentication Code: ");

            var authCode = Console.ReadLine();

            _token = await TokenFactory.GetToken(authCode, _app);

            Console.WriteLine("Access token generated");

            ShowDashLine();

            var host = ApiInfo.GetHost(mode);

            _client = new OpenClient(host, ApiInfo.Port, TimeSpan.FromSeconds(10));

            _disposables.Add(_client.Where(iMessage => iMessage is not ProtoHeartbeatEvent).Subscribe(OnMessageReceived, OnException));
            _disposables.Add(_client.OfType <ProtoOAErrorRes>().Subscribe(OnError));
            _disposables.Add(_client.OfType <ProtoOARefreshTokenRes>().Subscribe(OnRefreshTokenResponse));

            Console.WriteLine("Connecting Client...");

            await _client.Connect();

            ShowDashLine();

            Console.WriteLine("Client successfully connected");

            ShowDashLine();

            Console.WriteLine("Sending App Auth Req...");

            Console.WriteLine("Please wait...");

            ShowDashLine();

            var applicationAuthReq = new ProtoOAApplicationAuthReq
            {
                ClientId     = _app.ClientId,
                ClientSecret = _app.Secret,
            };

            await _client.SendMessage(applicationAuthReq, ProtoOAPayloadType.ProtoOaApplicationAuthReq);

            await Task.Delay(5000);

            Console.WriteLine("You should see the application auth response message before entering any command");

            Console.WriteLine("For commands list and description use 'help' command");

            ShowDashLine();

            GetCommand();
        }
 internal ConfigurationOperations(ApiClient client, TokenFactory tokenFactory)
 {
     _client       = client ?? throw new ArgumentNullException(nameof(client));
     _tokenFactory = tokenFactory ?? throw new ArgumentNullException(nameof(tokenFactory));
 }
Esempio n. 9
0
 public myUSLibor12M(DateTime argPricingDate)
     : base(PricingDate_: argPricingDate, Period_: new Period(12, TimeUnit.Months), argDBID_: TokenFactory.New(Bloomberg: "US0012M Index"), FixingDays_: 2, BDC_: BusinessDayConvention.ModifiedFollowing, DayCounter_: new Thirty360())
 {
 }
Esempio n. 10
0
 IToken CreateToken(string tokenName) => TokenFactory.Create(GetTokenType(tokenName), "");
Esempio n. 11
0
            Queue <Token> GetPostFix(string input, TokenFactory tokenFactory)
            {
                Queue <Token> output   = new Queue <Token>();
                Stack <Token> stack    = new Stack <Token>();
                int           position = 0;

                while (position < input.Length)
                {
                    Token token = GetNextToken(ref position, input, tokenFactory);
                    if (token == null)
                    {
                        break;
                    }
                    if (token is NumberBase)
                    {
                        output.Enqueue(token);
                    }
                    else if (token is FunctionBase)
                    {
                        stack.Push(token);
                    }
                    else if (token is LeftBracket)
                    {
                        stack.Push(token);
                    }
                    else if (token is RightBracket)
                    {
                        while (true)
                        {
                            Token taken = stack.Pop();
                            if (!(taken is LeftBracket))
                            {
                                output.Enqueue(taken);
                            }
                            else
                            {
                                break;
                            }
                        }
                    }
                    else if (token is OperatorBase)
                    {
                        if (stack.Count > 0)
                        {
                            Token top    = stack.Peek();
                            bool  nested = true;
                            while (nested)
                            {
                                if (top == null || !(top is OperatorBase))
                                {
                                    break;
                                }
                                OperatorBase o1 = (OperatorBase)token;
                                OperatorBase o2 = (OperatorBase)top;
                                if (o1.Side == Side.Left && (o2.Precedence >= o1.Precedence))
                                {
                                    output.Enqueue(stack.Pop());
                                }
                                else if (o2.Side == Side.Right && (o2.Precedence > o1.Precedence))
                                {
                                    output.Enqueue(stack.Pop());
                                }
                                else
                                {
                                    nested = false;
                                }
                                top = (stack.Count > 0) ? stack.Peek() : null;
                            }
                        }
                        stack.Push(token);
                    }
                }
                while (stack.Count > 0)
                {
                    Token next = stack.Pop();
                    if (next is LeftBracket || next is RightBracket)
                    {
                        throw new ArgumentException(InvalidMessage);
                    }
                    output.Enqueue(next);
                }
                return(output);
            }
Esempio n. 12
0
        private static IEnumerable <IToken> Lex(CodeFile file, Diagnostics diagnostics)
        {
            var code       = file.Code;
            var text       = code.Text;
            var tokenStart = 0;
            var tokenEnd   = -1; // One past the end position to allow for zero length spans

            while (tokenStart < text.Length)
            {
                var currentChar = text[tokenStart];
                switch (currentChar)
                {
                case '{':
                    yield return(TokenFactory.OpenBrace(SymbolSpan()));

                    break;

                case '}':
                    yield return(TokenFactory.CloseBrace(SymbolSpan()));

                    break;

                case '(':
                    yield return(TokenFactory.OpenParen(SymbolSpan()));

                    break;

                case ')':
                    yield return(TokenFactory.CloseParen(SymbolSpan()));

                    break;

                case '[':
                case ']':
                case '|':
                case '&':
                case '@':
                case '`':
                case '$':
                    yield return(NewReservedOperator());

                    break;

                case ';':
                    yield return(TokenFactory.Semicolon(SymbolSpan()));

                    break;

                case ',':
                    yield return(TokenFactory.Comma(SymbolSpan()));

                    break;

                case '#':
                    switch (NextChar())
                    {
                    case '#':
                        // it is `##`
                        yield return(NewReservedOperator(2));

                        break;

                    case '(':
                        // it is `#(`
                        yield return(NewReservedOperator(2));

                        break;

                    case '[':
                        // it is `#[`
                        yield return(NewReservedOperator(2));

                        break;

                    case '{':
                        // it is `#{`
                        yield return(NewReservedOperator(2));

                        break;

                    default:
                        // it is `#`
                        yield return(NewReservedOperator());

                        break;
                    }
                    break;

                case '.':
                    if (NextChar() is '.')
                    {
                        if (CharAt(2) is '<')
                        {
                            // it is `..<`
                            yield return(TokenFactory.DotDotLessThan(SymbolSpan(3)));
                        }
                        else
                        {
                            // it is `..`
                            yield return(TokenFactory.DotDot(SymbolSpan(2)));
                        }
                    }
                    else
                    {
                        yield return(TokenFactory.Dot(SymbolSpan()));
                    }
                    break;

                case ':':
                    if (NextChar() is ':' && CharAt(2) is '.')
                    {
                        // it is `::.`
                        yield return(TokenFactory.ColonColonDot(SymbolSpan(3)));
                    }
                    else
                    {
                        // it is `:`
                        yield return(TokenFactory.Colon(SymbolSpan()));
                    }
                    break;
Esempio n. 13
0
 public AddNodeTransactionOperation(SqlConnection connection, TransactionTokenFactory factory)
     : base(connection, factory)
 {
     NewNodeToken = TokenFactory.CreateToken();
     ResultTokens.Add(NewNodeToken);
 }
Esempio n. 14
0
 /// <summary>
 /// stores the tokens and the referenceData for comparison
 /// </summary>
 /// <param name="tokens"></param>
 /// <param name="referenceData"></param>
 public ComparisonModel(IEnumerable <TokenWrapper> tokens, IEnumerable <SourceEntityData> referenceData, TokenFactory factory)
 {
     Tokens        = tokens;
     ReferenceData = referenceData;
     Factory       = factory;
 }
Esempio n. 15
0
 public TokenFactoryTests()
 {
     _tokenFactory = new TokenFactory(_key, _issuer, _audience);
 }
Esempio n. 16
0
 public myUSTN(DateTime argPricingDate)
     : base(PricingDate_: argPricingDate, Period_: new Period(1, TimeUnit.Days), argDBID_: TokenFactory.New(Bloomberg: "USDR2T Index"), FixingDays_: 1, BDC_: BusinessDayConvention.Following, DayCounter_: new Actual360())
 {
 }
Esempio n. 17
0
 public myFedFunds()
     : base(PricingDate_: DateTime.Today, Period_: new Period(1, TimeUnit.Days), argDBID_: TokenFactory.New(Bloomberg: "US00O/N Index"), FixingDays_: 0, BDC_: BusinessDayConvention.Following, DayCounter_: new Actual360())
 {
 }
        public void Can_Generate_Saml2_Symmetric_Token()
        {
            // Arrange
            var contract = Utilities.SetBasicSAMLContract<SymmetricSamlTokenContract>(_testInstance.X509Certificate);

            // Act
            var factory = new TokenFactory(_testInstance.IdentityConfigurationForTest);
            var wsTrustToken = factory.GenerateToken<GenericXmlSecurityToken>(contract);

            // Assert
            Assert.IsNotNull(wsTrustToken, "Outer token came back empty");
            Assert.IsNotEmpty(wsTrustToken.SecurityKeys);
            Assert.IsNotNull(wsTrustToken.SecurityKeys);
            Assert.IsTrue(wsTrustToken.SecurityKeys.Count > 0);
            var samlToken = (Saml2SecurityToken) wsTrustToken.ToSecurityToken();
            Assert.IsNotNull(samlToken, "SAML token came back empty");
            var statement =
                samlToken.Assertion.Statements.Where(s => s is Saml2AttributeStatement).Select(s => s).FirstOrDefault()
                    as
                    Saml2AttributeStatement;
            Assert.IsNotNull(statement);

            Assert.IsTrue(
                statement.Attributes.Any(
                    c =>
                        c.Name.Equals(XspaClaimTypes.SubjectIdentifier) &&
                        c.Values.Any(v => v.Equals(TestClaims.SubjectClaim))), "Subject Identifier incorrect");
            Assert.IsTrue(
                statement.Attributes.Any(
                    c =>
                        c.Name.Equals(XspaClaimTypes.OrganizationIdentifier) &&
                        c.Values.Any(v => v.Equals(TestClaims.OrganizationIdClaim.ToString()))),
                "Organization Identifier incorrect");
            Assert.IsTrue(
                statement.Attributes.Any(
                    c =>
                        c.Name.Equals(XspaClaimTypes.SubjectOrganization) &&
                        c.Values.Any(v => v.Equals(TestClaims.OrganizationClaim))), "Subject Organization incorrect");
            Assert.IsTrue(
                statement.Attributes.Any(
                    c =>
                        c.Name.Equals(XspaClaimTypes.SubjectRole) &&
                        c.Values.Any(v => v.Contains(TestClaims.SubjectRoleClaim.Code))),
                "Subject Role incorrect");
            Assert.IsTrue(
                statement.Attributes.Any(
                    c =>
                        c.Name.Equals(XspaClaimTypes.PurposeOfUse) &&
                        c.Values.Any(v => v.Contains(TestClaims.PurposeOfUseClaim.Code))),
                "Purpose of Use incorrect");
            Assert.IsTrue(
                statement.Attributes.Any(
                    c =>
                        c.Name.Equals(XspaClaimTypes.NationalProviderIdentifier) &&
                        c.Values.Any(v => v.Equals(TestClaims.NPIClaim))), "Npi incorrect");
        }
 public RefreshTokenViewModel(int userId)
 {
     UserId = userId;
     Token  = TokenFactory.GenerateToken(64);
 }
        public void Can_Write_JWT_Token()
        {
            // Arrange
            var contract = Utilities.SetBasicJWTContract(_testInstance.X509Certificate);

            // Act
            var factory = new TokenFactory(_testInstance.IdentityConfigurationForTest);
            var token = factory.GenerateToken<JwtSecurityToken>(contract);
            string tokenString = token.Write();

            // Assert
            Assert.IsNotEmpty(tokenString);
            Assert.AreEqual(tokenString.Count(i => i.Equals('.')), 2, "Encoded token string delimiter count failure");
        }
Esempio n. 21
0
 public AppDbContext(DbContextOptions <AppDbContext> options, TokenFactory tf) : base(options)
 {
 }
Esempio n. 22
0
        public TreeBuilderBase(Lifetime lifetime, ILexer lexer) : base(lifetime)
        {
            var tokenFactory = new TokenFactory(IdentifierIntern);

            Builder = new PsiBuilder(lexer, ElementType.F_SHARP_IMPL_FILE, tokenFactory, lifetime);
        }
Esempio n. 23
0
 public myUSLibor2W(DateTime argPricingDate)
     : base(PricingDate_: argPricingDate, Period_: new Period(2, TimeUnit.Weeks), argDBID_: TokenFactory.New(Bloomberg: "US0002W Index"), FixingDays_: 2, BDC_: BusinessDayConvention.ModifiedFollowing, DayCounter_: new Actual360())
 {
 }
Esempio n. 24
0
        public static void Main(string[] args)
        {
            var tokenFactory            = new TokenFactory();
            var environmentBlockFactory = new EnvironmentBlockFactory();
            var processFactory          = new ProcessFactory();

            const string username = "******";
            const string password = "******";

            GetOrCreateUser(username, password);

            using (var token = tokenFactory.Logon(username, ".", GetSecureString(password)))
            {
                using (var environmentBlockHandle = environmentBlockFactory.Create(token, false))
                {
                    var profileInfo = new ProfileInfo
                    {
                        Size        = Marshal.SizeOf(typeof(ProfileInfo)),
                        Username    = username,
                        DefaultPath = null,
                    };
                    token.LoadUserProfile(ref profileInfo);

                    IProcessInformation processInformation;
                    var processStartInfo = new ProcessStartInfo
                    {
                        Desktop = string.Empty,
                    };
                    string commandLine = string.Format("\"{0}\"", typeof(TestProgramWhileTrue.Program).Assembly.Location);

                    if (Environment.UserInteractive)
                    {
                        processInformation = processFactory.CreateWithLogin(username, "", password,
                                                                            ProcessLogonFlags.None,
                                                                            null,
                                                                            commandLine,
                                                                            ProcessCreationFlags.NewConsole | ProcessCreationFlags.UnicodeEnvironment,
                                                                            environmentBlockHandle,
                                                                            Environment.CurrentDirectory,
                                                                            processStartInfo);
                    }
                    else
                    {
                        processInformation = processFactory.CreateAsUser(token,
                                                                         null,
                                                                         commandLine,
                                                                         false,
                                                                         ProcessCreationFlags.NewConsole | ProcessCreationFlags.UnicodeEnvironment,
                                                                         environmentBlockHandle,
                                                                         Environment.CurrentDirectory,
                                                                         processStartInfo);
                    }

                    using (processInformation)
                    {
                        Console.WriteLine("Press any key to kill");
                        Console.ReadKey(intercept: true);
                        processInformation.Process.Terminate(0);

                        token.UnloadUserProfile(ref profileInfo);
                        token.DeleteUserProfile();
                        DeleteUser(username);
                    }
                }
            }
        }
Esempio n. 25
0
 public GameHub(GameService gameService, TokenFactory tokenFactory, ILogger <GameHub> logger)
 {
     _gameService  = gameService;
     _tokenFactory = tokenFactory;
     _logger       = logger;
 }