Module: J1App

Defined in:
lib/j1_app.rb,
lib/j1_app/j1_auth_manager/config.rb,
lib/j1_app/j1_auth_manager/helpers.rb,
lib/j1_app/j1_auth_manager/commands.rb,
lib/j1_app/j1_auth_manager/error_pages.rb,
lib/j1_app/j1_site_manager/static_site.rb,
lib/j1_app/j1_auth_manager/auth_manager.rb,
lib/j1_app/j1_auth_manager/helpers_disqus.rb,
lib/j1_app/j1_auth_manager/helpers_github.rb,
lib/j1_app/j1_auth_manager/helpers_patreon.rb,
lib/j1_app/j1_auth_manager/helpers_twitter.rb,
lib/j1_app/j1_auth_manager/helpers_facebook.rb,
lib/j1_app/j1_site_manager/static_site.no-cross-origin.rb

Overview


~/lib/j1_app/j1_auth_manager/omniauth/strategies/helpers_facebook.rb

Provides helper methods for the facebook omniauth strategy

Product/Info: jekyll.one

Copyright © 2023, 2024 Juergen Adams

J1 Theme is licensed under the MIT License See: github.com/jekyll-one-org/j1-template/blob/main/LICENSE


NOTES


Defined Under Namespace

Modules: DisqusHelpers, ErrorPages, FacebookHelpers, GithubHelpers, Helpers, PatreonHelpers, TwitterHelpers Classes: AuthManager, Commands, ConfigError, SiteManager

Class Method Summary collapse

Class Method Details

.active_providersObject



116
117
118
# File 'lib/j1_app/j1_auth_manager/config.rb', line 116

def self.active_providers
  auth_config['providers']['activated']
end

.auth?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/j1_app/j1_auth_manager/config.rb', line 98

def self.auth?
  !!auth_config['enabled']
end

.auth_configObject



89
90
91
92
# File 'lib/j1_app/j1_auth_manager/config.rb', line 89

def self.auth_config
  # @auth['settings']['j1_auth']
  auth_settings['j1_auth']
end

.auth_config_dataObject



44
45
46
47
48
# File 'lib/j1_app/j1_auth_manager/config.rb', line 44

def self.auth_config_data
  @auth ||= YAML.safe_load_file(auth_config_file)
rescue StandardError
  {}
end

.auth_config_fileObject



39
40
41
42
# File 'lib/j1_app/j1_auth_manager/config.rb', line 39

def self.auth_config_file
  # File.join(Dir.pwd, '_data/modules/authentication.yml')
  File.join(J1App.project_path, '_data/modules/authentication.yml')
end

.auth_settingsObject



85
86
87
# File 'lib/j1_app/j1_auth_manager/config.rb', line 85

def self.auth_settings
  auth_config_data.fetch('settings', {})
end

.conditions(arg) ⇒ Object



145
146
147
148
149
150
151
152
153
# File 'lib/j1_app/j1_auth_manager/config.rb', line 145

def self.conditions (arg)
  condition_profile = {}
  provider = arg
  provider_conditions = auth_config['providers']["#{provider}"]['conditions']
  provider_conditions.each do |key, value|
    condition_profile[key] = value
  end
  condition_profile
end

.default_providerObject



120
121
122
# File 'lib/j1_app/j1_auth_manager/config.rb', line 120

def self.default_provider
  auth_config['providers']['activated'][0]
end

.destinationObject



80
81
82
83
# File 'lib/j1_app/j1_auth_manager/config.rb', line 80

def self.destination
  # jekyll_config.fetch('destination', File.expand_path('_site', Dir.pwd))
  jekyll_config.fetch('destination', File.expand_path(J1App.project_path, '_site'))
end

.get_condition(arg) ⇒ Object



141
142
143
# File 'lib/j1_app/j1_auth_manager/config.rb', line 141

def self.get_condition(arg)
  auth_config['provider']['condition']["#{arg}"]
end

.jekyll_configObject



33
34
35
36
37
# File 'lib/j1_app/j1_auth_manager/config.rb', line 33

def self.jekyll_config
  @config ||= YAML.safe_load_file(jekyll_config_file)
rescue StandardError
  {}
end

.jekyll_config_fileObject



27
28
29
30
31
# File 'lib/j1_app/j1_auth_manager/config.rb', line 27

def self.jekyll_config_file
  # File.join(Dir.pwd, "_config.develop.yml")
  # File.join(Dir.pwd, '_config.yml')
  File.join(J1App.project_path, '_config.yml')
end

.middleware_dataObject



72
73
74
# File 'lib/j1_app/j1_auth_manager/config.rb', line 72

def self.middleware_data
  private_data.fetch('middleware', {})
end

.oauth_dataObject



76
77
78
# File 'lib/j1_app/j1_auth_manager/config.rb', line 76

def self.oauth_data
  middleware_data.fetch('oauth', {})
end

.permissionsObject



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/j1_app/j1_auth_manager/config.rb', line 124

def self.permissions
  permission_profile = {
      :protected   => [],
      :private   => []
  }

  active_providers = auth_config['providers']['activated']

  active_providers.each { |p|
    provider_permissions = auth_config['providers']["#{p}"]['permissions']
    provider_permissions.each do |perm|
      permission_profile[:"#{perm}"] << "#{p}"
    end
  }
  permission_profile
end

.private_dataObject



66
67
68
69
70
# File 'lib/j1_app/j1_auth_manager/config.rb', line 66

def self.private_data
  @private_data ||= YAML.safe_load_file(template_private_data_file)
rescue StandardError
  {}
end

.project_pathObject

set j1 project path



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/j1_app/j1_auth_manager/config.rb', line 5

def self.project_path
  # set project folder to the path set by ENV var J1_PROJECT_HOME (preferred)
  #
  if ENV['J1_PROJECT_HOME'] != nil
    ENV['J1_PROJECT_HOME']
  elsif ARGV.grep(/config.ru/)[0] != nil
    # set project folder to path of ARGV argument for config.ru if available.
    # This will work, if the app is called from commandline (rackup)
    #
    File.dirname(ARGV.grep(/config.ru/)[0])
  else
    # set project folder if app is called from application manager
    # (e.g. passenger) to current work dir
    # NOTE:
    #   Unclear why File.join resolves the PATH correctly
    #   but File.dirname doesn't:
    #     File.dirname(Dir.pwd)
    #
    File.join(Dir.pwd, "")
  end
end

.public_contentObject



111
112
113
114
# File 'lib/j1_app/j1_auth_manager/config.rb', line 111

def self.public_content
  public_content = auth_config['content']['public']
  Regexp.new(public_content.join("|")) unless public_content.nil?
end

.siteObject



67
68
69
70
71
72
73
74
# File 'lib/j1_app.rb', line 67

def self.site
  Rack::Builder.new do
    use Rack::ShowExceptions                                                  # Middleware. Generate web-based error pages (for Rack)
    use Rack::Deflater                                                        # Middleware. Enable gzip compression for ALL web servers out of Rack
    use J1App::AuthManager                                                    # Middleware. Support authentication methods using OmniAuth
    run J1App::SiteManager                                                    # Run J1App Manager to manage the (static) site as an (Rack-based) Web Application:
  end
end

.ssl?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/j1_app/j1_auth_manager/config.rb', line 102

def self.ssl?
  !!auth_config['ssl']
end

.template_configObject



55
56
57
58
59
# File 'lib/j1_app/j1_auth_manager/config.rb', line 55

def self.template_config
  @template_config ||= YAML.safe_load_file(template_config_file)
rescue StandardError
  {}
end

.template_config_fileObject



50
51
52
53
# File 'lib/j1_app/j1_auth_manager/config.rb', line 50

def self.template_config_file
  # File.join(Dir.pwd, '_data/j1_config.yml')
  File.join(J1App.project_path, '_data/j1_config.yml')
end

.template_private_data_fileObject



61
62
63
64
# File 'lib/j1_app/j1_auth_manager/config.rb', line 61

def self.template_private_data_file
  # File.join(Dir.pwd, '_data/private.yml')
  File.join(J1App.project_path, '_data/private.yml')
end

.user_settingsObject



94
95
96
# File 'lib/j1_app/j1_auth_manager/config.rb', line 94

def self.
  template_config.fetch('user', {})
end

.whitelistObject



106
107
108
109
# File 'lib/j1_app/j1_auth_manager/config.rb', line 106

def self.whitelist
  whitelist = auth_config['whitelist']
  Regexp.new(whitelist.join("|")) unless whitelist.nil?
end