LoginSignup
19
20

More than 5 years have passed since last update.

ElectronでQiitaへOAuth接続してみた

Last updated at Posted at 2016-01-11

Qiitaにつなげてみた。レンダラから使う場合

var remote = require('remote');
var request = require('request');
var BrowserWindow = remote.require('browser-window');

var qiitaUrl = "https://qiita.com/api/v2/oauth/authorize?client_id=[自分のクライアントID]&scope=write_qiita";
var authWindow = new BrowserWindow({width: 800, height: 600});
authWindow.webContents.on('did-get-redirect-request', (event, oldUrl, newUrl) => {
  var matched;
  if(matched = newUrl.match(/\?code=([^&]*)/)) {
    var params = {
      'client_id': "xxxx",
      'client_secret': "xxxx",
      'code': matched[1],
    };

    var options = {
      url: 'https://qiita.com/api/v2/access_tokens',
      json: params
    };

    request.post(options, (error, response, body) => {
      /* body.token に入ってる */
    });
    setTimeout(() => {
      authWindow.close();
    }, 0);
  }
});

authWindow.on('closed', () => {
  /* ユーザーにウインドウをクローズされた */
});
authWindow.loadURL(qiitaUrl)
19
20
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
19
20