public async static Task<OAuth2Module> Create(Config config, SessionRepositry repository)
 {
     OAuth2Module module = new OAuth2Module();
     module.repository = repository;
     await module.init(config);
     return module;
 }
 public async Task init(Config config)
 {
     this.config = config;
     try
     {
         session = await repository.Read(config.accountId);
     }
     catch (IOException e)
     {
         session = new Session() { accountId = config.accountId };
     }
 }
        public async Task AddAccountTest()
        {
            //given
            string name = "test";
            Config config = new Config() { accountId = name };

            //when
            await AccountManager.AddAccount(config);

            //then
            Assert.IsNotNull(AccountManager.GetAccountByName(name));
        }
        public async Task GetByClientId()
        {
            //given
            string clientId = "test";
            Config config = new Config() { accountId = "dummy", clientId = clientId };

            //when
            var module1 = await AccountManager.AddAccount(config);
            var module2 = AccountManager.GetAccountByClientId(clientId);

            //then
            Assert.AreSame(module1, module2);
        }
 public static async Task<OAuth2Module> AddAccount(Config config)
 {
     if (Instance.modules.ContainsKey(config.accountId))
     {
         return Instance.modules[config.accountId];
     }
     else
     {
         OAuth2Module module = await OAuth2Module.Create(config);
         Instance.modules[config.accountId] = module;
         return module;
     }
 }
        public async Task AddAccountMultipleTimesTest()
        {
            //given
            string name = "test";
            Config config = new Config() { accountId = name };

            //when
            var module1 = await AccountManager.AddAccount(config);
            config.accessTokenEndpoint = "other";
            var module2 = await AccountManager.AddAccount(config);

            //then
            Assert.AreSame(module1, module2);
        }
 public async static Task<OAuth2Module> Create(Config config)
 {
     OAuth2Module module = new OAuth2Module();
     await module.init(config);
     return module; 
 }
 private async static Task RestoreAccount(Config config)
 {
     OAuth2Module module;
     if (config.GetType() == typeof(KeycloakConfig))
     {
         module = await KeycloakOAuth2Module.Create(config);
     }
     else if (config.GetType() == typeof(FacebookConfig))
     {
         module = await FacebookOAuth2Module.Create(config);
     }
     else
     {
         module = await OAuth2Module.Create(config);
     }
     
     Instance.modules[config.accountId] = module;
 }
 public async static new Task<OAuth2Module> Create(Config config)
 {
     FacebookOAuth2Module module = new FacebookOAuth2Module();
     await module.init(config);
     return module;
 }