public FastReader() { try { this.Inbox = new Inbox(new InboxOptions(recordRealtimeTextLog: true)); this.Inbox.StateChangeEventListener.RegisterCallback(async(caller, type, state, args) => { UpdatedCallback(); await Task.CompletedTask; }); this.AccountsHive = Hive.LocalAppSettingsEx["Accounts"]; this.AccountsHive.AccessData(true, k => { var initial = new AccountSettingList(); AccountSettingList o = k.Get("AccountList", initial) !; foreach (AccountSetting account in o.List) { if (account.ProviderName._IsSamei(Consts.InboxProviderNames.Slack_Old)) { account.ProviderName = Consts.InboxProviderNames.Slack_App; } InboxAdapter a = this.Inbox.AddAdapter(account.Guid, account.ProviderName, new InboxAdapterAppCredential { ClientId = account.AppClientId, ClientSecret = account.AppClientSecret }); if (account.UserAccessToken._IsFilled()) { a.Start(new InboxAdapterUserCredential { AccessToken = account.UserAccessToken }); } else if (account.ProviderName._IsSamei(Consts.InboxProviderNames.Slack_User)) { // Special: Slack legacy tokens a.Start(new InboxAdapterUserCredential()); } } }); } catch { this._DisposeSafe(); throw; } }
public async Task <IActionResult> AuthCallback(string code, string state) { if (code._IsEmpty() || state._IsEmpty()) { throw new ApplicationException($"この URL は認証サービスからのコールバック専用です。直接アクセスすることはできません。"); } string id = state; InboxAdapter adapter = Reader.GetAdapter(id); InboxAdapterUserCredential credential = await adapter.AuthGetCredentialAsync(code, this.GenerateAbsoluteUrl(nameof(AuthCallback))); adapter.Start(credential); Reader.SaveSettingsFile(); return(Redirect("/")); }
public IActionResult AuthStart(string id) { InboxAdapter adapter = Reader.GetAdapter(id); string callbackUrl = this.GenerateAbsoluteUrl(nameof(AuthCallback)); string authUrl = adapter.AuthStartGetUrl(callbackUrl, id); if (authUrl._IsEmpty()) { // No need to auth redirect adapter.Start(new InboxAdapterUserCredential()); Reader.SaveSettingsFile(); return(Redirect("/")); } return(Redirect(authUrl)); }