Skip to content

Commit

Permalink
0.9.15
Browse files Browse the repository at this point in the history
  • Loading branch information
burakakca committed Sep 18, 2021
1 parent 0ad9fee commit 0096dc5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 47 deletions.
2 changes: 1 addition & 1 deletion lib/omniauth/mastodon/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def minor
end

def patch
8
15
end

def pre
Expand Down
74 changes: 28 additions & 46 deletions lib/omniauth/strategies/mastodon.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,11 @@ class Mastodon < OmniAuth::Strategies::OAuth2
# Before we can redirect the user to authorize access, we must know where the user is from
# If the identifier param is not already present, a form will be shown for entering it
def request_phase
puts "++++++++++request_phase"
puts identifier ? "true" : "false"
puts options[:domain]
puts options[:client_id]
puts options[:client_secret]
puts "++++++++++request_phase"
identifier ? start_oauth : get_identifier
# identifier ? start_oauth : get_identifier
start_oauth
end

def callback_phase
puts "++++++++++callback_phase"
puts identifier
set_options_from_identifier
super
end
Expand All @@ -57,9 +50,6 @@ def raw_info

def callback_url
full_host + script_name + callback_path
puts "++++++++++callback_url"
puts identifier
puts full_host + script_name + callback_path
end

def authorize_params
Expand All @@ -70,30 +60,26 @@ def authorize_params

private

def get_identifier
I18n.with_locale(locale) do
form = OmniAuth::Form.new(title: translate('.omniauth.mastodon.title'))
form.text_field translate('.omniauth.mastodon.text'), 'identifier'
form.button translate('.omniauth.mastodon.button')
form.to_response
end
end

def translate(t)
I18n.exists?(t) ? I18n.t(t) : I18n.t(t, locale: :en)
end

def locale
loc = request.params['locale'] || session[:omniauth_login_locale] || I18n.default_locale
loc = :en unless I18n.locale_available?(loc)
loc
end
# def get_identifier
# I18n.with_locale(locale) do
# form = OmniAuth::Form.new(title: translate('.omniauth.mastodon.title'))
# form.text_field translate('.omniauth.mastodon.text'), 'identifier'
# form.button translate('.omniauth.mastodon.button')
# form.to_response
# end
# end

# def translate(t)
# I18n.exists?(t) ? I18n.t(t) : I18n.t(t, locale: :en)
# end

# def locale
# loc = request.params['locale'] || session[:omniauth_login_locale] || I18n.default_locale
# loc = :en unless I18n.locale_available?(loc)
# loc
# end

def start_oauth
puts "++++++++++start_oauth"
puts callback_url
puts authorize_params
puts "++++++++++start_oauth"
set_options_from_identifier
redirect client.auth_code.authorize_url({:redirect_uri => callback_url}.merge(authorize_params))
end
Expand All @@ -107,18 +93,14 @@ def identifier
end

def set_options_from_identifier
username, domain = identifier.split('@')
client_id, client_secret = options.credentials.call(domain, callback_url)
puts "*-**-*"
puts username
puts domain
puts client_id
puts client_secret
puts "*-**-*"
options.identifier = identifier
options.client_options[:site] = "https://#{domain}"
options.client_id = client_id
options.client_secret = client_secret
# username, domain = identifier.split('@')
domain = options[:domain]
# client_id, client_secret = options.credentials.call(domain, callback_url)
# options.identifier = identifier
# options.client_options[:site] = "http://#{domain}"
options.client_options[:site] = domain
# options.client_id = client_id
# options.client_secret = client_secret
end
end
end
Expand Down

0 comments on commit 0096dc5

Please sign in to comment.