示例#1
0
        protected override async Task <Account> PerformAuthenticate()
        {
            var account = CurrentOAuthAccount ?? GetAccount <SoundCloudAccount>(Identifier);

            //TODO: make a verification call
            if (account?.IsValid() ?? false)
            {
                try
                {
                    CurrentAccount = account;
                    var user = await GetUserInfo();

                    return(account);
                }
                catch (WebException webEx)
                {
                    Console.WriteLine(webEx);
                    return(CurrentAccount = account);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }

            authenticator = CreateAuthenticator();

            OAuthApi.ShowAuthenticator(authenticator);

            var token = await authenticator.GetAuthCode();

            if (string.IsNullOrEmpty(token))
            {
                throw new Exception("Null token");
            }
            account = await GetAccountFromAuthCode(authenticator, Identifier);

            account.Identifier = Identifier;
            SaveAccount(account);
            CurrentAccount = account;
            return(account);
        }