mirror of
https://github.com/wahyd4/gitlabhq.git
synced 2026-08-10 05:06:46 +10:00
Fix OAuth2 issue importing a new project from GitHub and GitLab
It appears that the GitLab OAuth2 client options were converted to strings instead of symbols when merged with the default options (i.e. `{}.merge(github_options)`). As a result, the OAuth2 defaults were being used. For example, the OAuth2 client options would have a key with `authorize_url` and `:authorize_url`, but the former was never used. As a result, the OAuth2 client would always use the wrong URL to talk to GitHub.
Note that this bug should also have affected GitLab, but not Bitbucket: The OAuth client is careful to convert all keys to symbols.
Closes #1268
See merge request !425
54 lines
1.2 KiB
Ruby
54 lines
1.2 KiB
Ruby
module Gitlab
|
|
module GithubImport
|
|
class Client
|
|
attr_reader :client, :api
|
|
|
|
def initialize(access_token)
|
|
@client = ::OAuth2::Client.new(
|
|
config.app_id,
|
|
config.app_secret,
|
|
github_options
|
|
)
|
|
|
|
if access_token
|
|
::Octokit.auto_paginate = true
|
|
@api = ::Octokit::Client.new(access_token: access_token)
|
|
end
|
|
end
|
|
|
|
def authorize_url(redirect_uri)
|
|
client.auth_code.authorize_url({
|
|
redirect_uri: redirect_uri,
|
|
scope: "repo, user, user:email"
|
|
})
|
|
end
|
|
|
|
def get_token(code)
|
|
client.auth_code.get_token(code).token
|
|
end
|
|
|
|
def method_missing(method, *args, &block)
|
|
if api.respond_to?(method)
|
|
api.send(method, *args, &block)
|
|
else
|
|
super(method, *args, &block)
|
|
end
|
|
end
|
|
|
|
def respond_to?(method)
|
|
api.respond_to?(method) || super
|
|
end
|
|
|
|
private
|
|
|
|
def config
|
|
Gitlab.config.omniauth.providers.find{|provider| provider.name == "github"}
|
|
end
|
|
|
|
def github_options
|
|
OmniAuth::Strategies::GitHub.default_options[:client_options].symbolize_keys
|
|
end
|
|
end
|
|
end
|
|
end
|