0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Slackbotを配布するための、OAuth認証をするためのスクリプト

Posted at

SlackBotを配布するためにはSlackのoauth.accessAPIを叩く必要がありますが、サーバを用意するのも面倒だったため、スパッとGoogle Apps Scriptで書きました。
Google Apps Scriptを新規で作成して、そのファイルのURLをOAuth & PermissionsのRedirect URLsに追加します。
Google Apps Scriptの中身は下記のClientIDとClientSecretを編集したあとコピペしてください。
これでSlackBotを配布する準備ができました。簡単。

var CLIENT_ID = "YOUR CLIENT_ID";
var CLIENT_SECRET = "YOUR CLIENT_SECRET";

function doGet(request) {
  try {
    var payload = {
      "client_id": CLIENT_ID,
      "client_secret": CLIENT_SECRET,
      "code": request.parameter.code
    };
    UrlFetchApp.fetch("https://slack.com/api/oauth.access", {
      "method": "post",
      "contentType": "application/x-www-form-urlencoded",
      "payload": payload
    });
    return HtmlService.createTemplateFromFile("result").evaluate();
  } catch(error) {
    // error handling
  }
}

result.html(oauth認証成功後に表示させるHTML)

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
  </head>
  <body>
    認証が成功しました。
  </body>
</html>
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?