From b93568c740e6bd1dcfb592057fd4dca9a43428f3 Mon Sep 17 00:00:00 2001 From: Ashwin Maroli Date: Sat, 28 Jul 2018 00:32:43 +0530 Subject: [PATCH] Use Octokit to generate installation access token (#60) --- Gemfile | 2 ++ github/token | 20 ++++---------------- 2 files changed, 6 insertions(+), 16 deletions(-) diff --git a/Gemfile b/Gemfile index 3c94252..1be4b7f 100644 --- a/Gemfile +++ b/Gemfile @@ -10,6 +10,8 @@ else gem "jekyll", git: repo, branch: "master" end +gem "octokit" + gem "jekyll-sass-converter" gem "kramdown" gem "jekyll-commonmark-ghpages" diff --git a/github/token b/github/token index 1f67a28..664ec96 100755 --- a/github/token +++ b/github/token @@ -2,11 +2,9 @@ # frozen_string_literal: true require "English" -require "json" require "jwt" # https://rubygems.org/gems/jwt -require "net/http" +require "octokit" require "openssl" -require "uri" # Private key contents get_secret = File.expand_path("../aws/secretsmanager/get", __dir__) @@ -25,18 +23,8 @@ payload = { } jwt = JWT.encode(payload, private_key, "RS256") - +client = Octokit::Client.new(:bearer_token => jwt) installation = ENV.fetch("INSTALLATION") +token = client.create_installation_access_token(installation)[:token] -uri = URI("https://api.github.com/installations/#{installation}/access_tokens") -req = Net::HTTP::Post.new(uri) -req["Authorization"] = "Bearer #{jwt}" -req["Accept"] = "application/vnd.github.machine-man-preview+json" - -http = Net::HTTP.new(uri.hostname, uri.port) -http.use_ssl = (uri.scheme == "https") -res = http.request(req) - -json = JSON.parse(res.body) - -puts json["token"] +puts token