Skip to content

Commit

Permalink
Use Octokit to generate installation access token (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
ashmaroli authored and pathawks committed Jul 27, 2018
1 parent 98ede77 commit b93568c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ else
gem "jekyll", git: repo, branch: "master"
end

gem "octokit"

gem "jekyll-sass-converter"
gem "kramdown"
gem "jekyll-commonmark-ghpages"
Expand Down
20 changes: 4 additions & 16 deletions github/token
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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

0 comments on commit b93568c

Please sign in to comment.