Files
grecia/lib/omni_auth/strategies/wordpress.rb
Javi Martín d8faa4f4d0 Follow Zeitwerk conventions for file structure
Even though we don't load this file with Zeitwerk, we're doing it for
consistency.

If we tried to load this file using Zeitwerk, without this change we'd
get an error:

```
NameError: uninitialized constant OmniauthWordpress
```
2024-04-11 19:08:02 +02:00

41 lines
911 B
Ruby

# This code is based on this gem https://github.com/jwickard/omniauth-wordpress-oauth2-plugin
require "omniauth-oauth2"
module OmniAuth
module Strategies
class Wordpress < OmniAuth::Strategies::OAuth2
option :name, "wordpress_oauth2"
option :client_options, {}
uid { raw_info["ID"] }
info do
{
name: raw_info["display_name"],
email: raw_info["user_email"],
nickname: raw_info["user_nicename"],
urls: { "Website" => raw_info["user_url"] }
}
end
extra do
{ raw_info: raw_info }
end
def callback_url
full_host + script_name + callback_path
end
def raw_info
@raw_info ||= obtain_raw_info
end
def obtain_raw_info
access_token.get("/oauth/me", params: { "Authorization" => "Bearer #{access_token.token}" }).parsed
end
end
end
end