Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OAuth で複数ワークスペースにインストールできるようにする #43

Closed
mashabow opened this issue Sep 25, 2021 · 4 comments · Fixed by #46
Closed

OAuth で複数ワークスペースにインストールできるようにする #43

mashabow opened this issue Sep 25, 2021 · 4 comments · Fixed by #46

Comments

@mashabow
Copy link
Owner Author

mashabow commented Oct 4, 2021

移行作業

Firebase Functions の config

Client ID と Client Secret を追加

$ firebase functions:config:set \
    slack.client_id="012345678.1234567..." \
    slack.client_secret="01234567890abcdef..."

適当な値の state secret を設定

$ firebase functions:config:set rota.state_secret="01234567890abcdef..."

bot token を Function の config から削除

$ firebase functions:config:unset slack.bot_token

再デプロイ

$ firebase deploy --only functions

@mashabow
Copy link
Owner Author

mashabow commented Oct 4, 2021

Firestore のマイグレーション

Rotation の新しいフィールド installationId に、ワークスペースの ID(例:T000000)を一律セットしたい。

今回は fireway を使ってみる(参考)。

$ yarn global add fireway

サービスアカウントとその鍵を作成して、ローカルの環境変数 GOOGLE_APPLICATION_CREDENTIALS に設定。

$ export GOOGLE_APPLICATION_CREDENTIALS="/home/user/Downloads/service-account-file.json"

マイグレーション処理を記述した migrations/v0.0.1__set-installationId.js を作成。

module.exports.migrate = async ({ firestore }) => {
  const rotationsRef = await firestore.collection("rotations").get();
  await Promise.all(
    rotationsRef.docs.map((doc) =>
      doc.ref.update({ installationId: "T000000" })
    )
  );
};

dryrun。

$ fireway migrate --dryrun
Found 1 migration files
Making firestore read-only
Executing 1 migration files
Running v0.0.1__set-installationId.js
Updating rotations/1596764607560 {"installationId":"T000000"}
Updating rotations/1597627527824 {"installationId":"T000000"}
Updating rotations/1598233875660 {"installationId":"T000000"}
(略)
Updating rotations/1632881658931 {"installationId":"T000000"}
Uploading the results for v0.0.1__set-installationId.js
Setting fireway/0-0.0.1-set-installationId {"installed_rank":0,"description":"set-installationId","version":"0.0.1","script":"v0.0.1__set-installationId.js","type":"js","checksum":"0e6ebd4d4ba744f97acae0647fc8fa0e","installed_by":"mashabow","installed_on":"2021-10-04T15:57:33.722Z","execution_time":80,"success":true}
Finished all firestore migrations
Files scanned:1 executed:1
Docs added:0 created:0 updated:28 set:0 deleted:0

よさそうだったので実際に実行。

$ fireway migrate
Found 1 migration files
Executing 1 migration files
Running v0.0.1__set-installationId.js
Updating rotations/1596764607560 {"installationId":"T000000"}
Updating rotations/1597627527824 {"installationId":"T000000"}
Updating rotations/1598233875660 {"installationId":"T000000"}
(略)
Updating rotations/1632881658931 {"installationId":"T000000"}
Uploading the results for v0.0.1__set-installationId.js
Setting fireway/0-0.0.1-set-installationId {"installed_rank":0,"description":"set-installationId","version":"0.0.1","script":"v0.0.1__set-installationId.js","type":"js","checksum":"ac7633f1604ca3fc92a2f65b7987efe9","installed_by":"mashabow","installed_on":"2021-10-04T16:02:43.287Z","execution_time":247,"success":true}
Finished all firestore migrations
Files scanned:1 executed:1
Docs added:0 created:0 updated:28 set:0 deleted:0

@mashabow
Copy link
Owner Author

mashabow commented Oct 4, 2021

Slack App の設定

OAuth & Permissions

Redirect URLs を追加。画像では切れているが、パスは /slack/oauth_redirect

Slack_API__Applications___feedforce_Slack

Manage Distribution

Share Your App with Other Workspaces > Remove Hard Coded Information にチェックを入れ、[Activate Public Distribution] をクリック

Slack___Slack_API__Applications___feedforce

@mashabow
Copy link
Owner Author

mashabow commented Oct 4, 2021

ワークスペースへインストール

Untitled.mov

ちなみに、インストール直後はアプリのホーム画面が開く。

Slack___Rota___feedforce

Firestore に installation が保存され、bot token が入っていることを確認 ✅

slack-app-rota_-_Cloud_Firestore_-_Firebase_コンソール

追記:bot token は暗号化して保存するようにした。#48 参照。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant