public async Task Authentication(Uri instanceUri, string consumerKey, string consumerSecret)
        {
            string url = instanceUri.ToString();

            if (string.IsNullOrEmpty(consumerKey))
            {
                var clientKey = await ClientKeyManager.GetMastodonKey(instanceUri.Host);

                var cachecClientKey = App.Setting.ClientKeys
                                      .Where(key => key.Service == ServiceType.Mastodon)
                                      .FirstOrDefault(key => string.Equals(key.Host, instanceUri.ToString(), StringComparison.OrdinalIgnoreCase));

                if (cachecClientKey == null)
                {
                    App.Setting.ClientKeys.Add(new ClientKeyCache(instanceUri, clientKey));

                    consumerKey    = clientKey.ClientId;
                    consumerSecret = clientKey.ClientSecret;
                }
                else
                {
                    consumerKey    = cachecClientKey.ClientId;
                    consumerSecret = cachecClientKey.ClientSecret;
                }
            }

            this._api = new MastodonApi(instanceUri, consumerKey, consumerSecret);

            this.AuthorizeUrl = this._api.OAuth.GetAuthorizeUrl(ApiScopes);

            App.Open(this.AuthorizeUrl);
        }
Example #2
0
        public void UpdateApiTokens(MastodonApi api)
        {
            this.Api = api;

            var setting = this._setting;

            setting.ClientId     = api.ApiToken;
            setting.ClientSecret = api.ApiTokenSecret;
            setting.AccessToken  = api.AccessToken;
        }
        public async Task GetAccessToken(string code)
        {
            Uri    host           = this._api.HostUrl;
            string consumerKey    = this._api.ClientId;
            string consumerSecret = this._api.ClientSecret;

            var res = await this._api.OAuth.GetAccessToken(code).ConfigureAwait(false);

            this._api = new MastodonApi(host, consumerKey, consumerSecret, res.AccessToken);
        }
Example #4
0
        public MastodonAccount(MastodonAccountSetting item)
            : base(false)
        {
            this._setting     = item.Clone();
            this.ItemId       = item.ItemId;
            this.Api          = item.CreateApi();
            this.InstanceHost = item.InstanceUrl.Host;
            this.DataStore    = new MastodonDataManager(item.InstanceUrl);
            this.Info         = this.DataStore.GetAccount(item);
            this.Timeline     = new MastodonTimeline(this);
            this.Commands     = new AccountCommandGroup(this);

            ((INotifyPropertyChanged)this.Info).PropertyChanged += this.OnProfileUpdated;
        }
Example #5
0
        public MastodonAccount(string itemId, MastodonApi api, Account account)
            : base(true)
        {
            this._setting = new()
            {
                ItemId      = itemId,
                InstanceUrl = api.HostUrl,
                Id          = account.Id,
            };
            this.ItemId = itemId;
            this.Api    = api;
            this.UpdateApiTokens(api);
            this.InstanceHost = api.HostUrl.Host;
            this.DataStore    = new MastodonDataManager(api.HostUrl);
            this.Info         = this.DataStore.RegisterAccount(account);
            this.Timeline     = new MastodonTimeline(this);
            this.Commands     = new AccountCommandGroup(this);
            this.OnProfileUpdated(this.Info, new(null));

            ((INotifyPropertyChanged)this.Info).PropertyChanged += this.OnProfileUpdated;
        }
 internal InstancesApi(MastodonApi tokens) : base(tokens)
 {
 }
Example #7
0
 internal FollowsApi(MastodonApi tokens) : base(tokens)
 {
 }
 internal FavouritesApi(MastodonApi tokens) : base(tokens)
 {
 }
 internal TimelinesApi(MastodonApi tokens) : base(tokens)
 {
 }
Example #10
0
 internal SearchApi(MastodonApi tokens) : base(tokens)
 {
 }
Example #11
0
 internal ListsApi(MastodonApi tokens) : base(tokens)
 {
 }
 internal StatusesApi(MastodonApi tokens) : base(tokens)
 {
 }
Example #13
0
 public MastodonApiGateway(MastodonAccount account)
 {
     this._account = account;
     this._api     = account.Api;
 }
Example #14
0
 internal ReportsApi(MastodonApi tokens) : base(tokens)
 {
 }
 internal FollowRequestsApi(MastodonApi tokens) : base(tokens)
 {
 }
 internal AccountsApi(MastodonApi tokens) : base(tokens)
 {
 }
Example #17
0
 internal MediaApi(MastodonApi tokens) : base(tokens)
 {
 }
Example #18
0
 internal OAuthApi(MastodonApi tokens) : base(tokens)
 {
     this._oauthBaseUrl = new Uri(tokens.HostUrl, "oauth/");
 }
Example #19
0
 public void GetDefaultHttpClient_DoesNotReturnNull()
 {
     Assert.NotNull(MastodonApi.GetDefaultHttpClient());
 }
Example #20
0
 internal BlocksApi(MastodonApi tokens) : base(tokens)
 {
 }
Example #21
0
 internal StreamingApi(MastodonApi tokens) : base(tokens)
 {
 }