Ejemplo n.º 1
0
        public async void TestRefreshAndAccessTokens()
        {
            var org = await this.fixture.Ident.CreateOrganization(new Organization
            {
                Name = "test organization"
            });

            var accessRefreshToken = await this.fixture.Ident.CreateToken(new JWTToken
            {
                Scope          = "offline_access",
                OrganizationId = org.Id
            });

            Assert.NotNull(accessRefreshToken.AccessToken);
            Assert.NotNull(accessRefreshToken.RefreshToken);
            Assert.NotNull(accessRefreshToken.ExpiresIn);
            Assert.Equal("offline_access", accessRefreshToken.Scope);

            var accessTokenIdent = Ident.InitIdent(accessRefreshToken.RefreshToken);
            var accessToken      = await accessTokenIdent.CreateToken(new JWTToken
            {
                GrantType = "refresh_token"
            });

            Assert.NotNull(accessToken.AccessToken);
            Assert.NotNull(accessToken.ExpiresIn);
        }
Ejemplo n.º 2
0
    public static async Task <Vault> InitVaultWithOrgToken()
    {
        var token = await TestUtil.CreateIdentForTestUser();

        var ident = Ident.InitIdent(token);
        var org   = await ident.CreateOrganization(new Organization
        {
            Name = "test org"
        });

        var orgToken = await ident.CreateToken(new JWTToken { OrganizationId = org.Id });

        return(Vault.InitVault(orgToken.Token));
    }
Ejemplo n.º 3
0
 public Baseline(string token)
 {
     this.ident  = Ident.InitIdent(token);
     this.nchain = NChain.InitNChain(token);
     this.resolveConnector(token);
 }
Ejemplo n.º 4
0
        public async Task <(bool, byte[])> AuthenticateOrgAsync(string email, string password)
        {
            bool isAuthenticated = false;

            byte[] token = null;

            try
            {
                _logger.LogTrace("calling Ident Authenticate");
                var userAuthResponse = await Ident.Authenticate(email, password);

                if (userAuthResponse.Item1 == 201)
                {
                    _logger.LogInformation(String.Format("Ident Authentication succesful for email {0}", email), userAuthResponse);

                    var tkn_dict = JsonConvert.DeserializeObject <Dictionary <string, Dictionary <string, object> > >(userAuthResponse.Item2);
                    if (tkn_dict.ContainsKey("token"))
                    {
                        var tkn_dict_inner = tkn_dict["token"];
                        if (tkn_dict_inner.ContainsKey("token"))
                        {
                            var tkn_str = tkn_dict_inner["token"];

                            _logger.LogTrace("calling InitIdent");
                            this._ident = Ident.InitIdent(tkn_str.ToString());

                            var orgId = await this.fetchDefaultOrganizationIdAsync();

                            if (orgId != null)
                            {
                                token = await this.vendOrganizationJWTAsync(orgId);
                            }

                            isAuthenticated = token != null;

                            if (isAuthenticated)
                            {
                                _logger.LogInformation(String.Format("Token Vending Authentication succesful for email {0}", email));

                                _repository.UpdateParticipants(email, Encoding.UTF8.GetString(token));
                            }
                        }
                        else
                        {
                            _logger.LogError("Inner dictionary of Ident response does not contain 'token' key");
                        }
                    }
                    else
                    {
                        _logger.LogError("Ident response does not contain 'token' key");
                    }
                }
                else
                {
                    _logger.LogError("Ident Authentication did not work: {0}, {1}", userAuthResponse.Item1, userAuthResponse.Item2);
                }
            }
            catch (Exception ex)
            {
                _logger.LogCritical(ex, "Unexpected Exception in Authenticate");
            }

            return(isAuthenticated, token);
        }