Method: Boxen::Preflight::Creds#run

Defined in:
lib/boxen/preflight/creds.rb

#runObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/boxen/preflight/creds.rb', line 69

def run
  
  tokens = get_tokens

  # Boxen now supports the updated GitHub Authorizations API by using a unique
  # `fingerprint` for each Boxen installation for a user. We delete any older
  # authorization that does not make use of `fingerprint` so that the "legacy"
  # authorization doesn't persist in the user's list of personal access
  # tokens.
  legacy_auth = tokens.detect { |a| a.note == "Boxen" && a.fingerprint == nil }
  tmp_api.delete_authorization(legacy_auth.id, :headers => headers) if legacy_auth

  # The updated GitHub authorizations API, in order to improve security, no
  # longer returns a plaintext `token` for existing authorizations. So, if an
  # authorization already exists for this machine we need to first delete it
  # so that we can create a new one.
  auth = tokens.detect { |a| a.note == note && a.fingerprint == fingerprint }
  tmp_api.delete_authorization(auth.id, :headers => headers) if auth

  auth = tmp_api.create_authorization(
    :note => note,
    :scopes => %w(repo user),
    :fingerprint => fingerprint,
    :headers => headers
  )

  config.token = auth.token

  unless ok?
    puts
    abort "Something went terribly wrong.",
      "I was able to get your OAuth token, but was unable to use it."
  end
end