我试图为gollum配置基本的http身份验证,但我希望登录用户名用于git提交。
我已经修改了config.ru,以便基本身份验证工作,现在我只需要弄清楚如何实现以下功能:
session['gollum.author'] => "%s" % loggedIn然后我可以去掉“约翰·史密斯”的绳子。
顺便说一句--请原谅这个愚蠢的问题,我以前从未碰过Ruby,现在已经很晚了。
#!/usr/bin/env ruby
#--------------------------------------------------------------------
# - example custom rack for the Gollum wiki engine
# - file should be placed in wiki root
# - RACK_APP environment variable should be set to the filename
# - entrypoint.sh script will run this app using:
# $ rackup $RACK_APP -p 4567
#--------------------------------------------------------------------
require 'rubygems'
require 'gollum/app'
gollum_path = File.expand_path(File.dirname(__FILE__))
wiki_options = {
:live_preview => false,
:allow_editing => true,
:allow_uploads => true,
:universal_toc => false,
}
users = {'user' => 'password'}
loggedIn = "anonymous"
use Rack::Auth::Basic, 'realm' do |username, password|
users.key?(username) && users[username] == password
loggedIn = username
end
Precious::App.set(:gollum_path, gollum_path)
Precious::App.set(:default_markup, :markdown)
Precious::App.set(:wiki_options, wiki_options)
run Precious::App
#set author
class Precious::App
before do
session['gollum.author'] = {
:name => "%s" % "john smith", # => "%s" % loggedIn
:email => "jsmith@example.com",
}
end
end因此,我可以看到会话只存在于Precious命名空间中,因此不能通过身份验证方法直接设置它:
use Rack::Auth::Basic, 'realm' do |username, password|
users.key?(username) && users[username] == password
session['gollum.author'] = {
:name => "%s" % "john smith", # => "%s" % username
:email => "jsmith@example.com",
}
end我也试过:
use Rack::Auth::Basic, 'realm' do |username, password|
users.key?(username) && users[username] == password
loggedIn = {
:name => "%s" % username,
:email => "jsmith@example.com",
}
end
Precious::App.set(:session['gollum.author'], loggedIn)发布于 2016-11-19 19:03:15
这里有一个解决方案,它允许您定义一系列用户,启用基本的http身份验证,并使用登录的用户名进行fit提交。
require 'rubygems'
require 'gollum/app'
gollum_path = File.expand_path(File.dirname(__FILE__))
wiki_options = {
:live_preview => false,
:allow_editing => true,
:allow_uploads => true,
:universal_toc => false,
}
users = {'user' => 'password',
'user2' => 'password2'}
use Rack::Auth::Basic, 'realm' do |username, password|
if users.key?(username) && users[username] == password
Precious::App.set(:loggedInUser, username)
end
end
Precious::App.set(:gollum_path, gollum_path)
Precious::App.set(:default_markup, :markdown)
Precious::App.set(:wiki_options, wiki_options)
run Precious::App
#set author
class Precious::App
before do
session['gollum.author'] = {
:name => "%s" % settings.loggedInUser,
:email => "%s@example.com" % settings.loggedInUser,
}
end
end发布于 2018-11-14 11:41:48
您可以简单地使用rubygem Gollum -auth向Gollum 4和5添加基本身份验证:
https://github.com/bjoernalbers/gollum-auth
只需用gem install gollum-auth或Bundler安装它,并在gollum之前加载它。下面是一个实现这一目标的示例机架config.ru (取自项目的自述文件):
#!/usr/bin/env ruby
require 'rubygems'
require 'gollum/auth' # Don't forget to load the gem!
require 'gollum/app'
# Define list of authorized users.
# Each user must have a username, password, name and email.
#
# Instead of a password you can also define a password_digest, which is the
# SHA-256 hash of a password.
#
# Example:
users = YAML.load %q{
---
- username: rick
password: asdf754&1129-@lUZw
name: Rick Sanchez
email: rick@example.com
- username: morty
password_digest: 5994471abb01112afcc18159f6cc74b4f511b99806da59b3caf5a9c173cacfc5
name: Morty Smith
email: morty@example.com
}
# Allow unauthenticated users to read the wiki (disabled by default).
options = { allow_unauthenticated_readonly: true }
# Allow only authenticated users to change the wiki.
# (NOTE: This must be loaded *before* Precious::App!)
use Gollum::Auth, users, options
# That's it. The rest is for gollum only.
gollum_path = File.expand_path(File.dirname(__FILE__)) # CHANGE THIS TO POINT TO YOUR OWN WIKI REPO
wiki_options = {:universal_toc => false}
Precious::App.set(:gollum_path, gollum_path)
Precious::App.set(:wiki_options, wiki_options)
run Precious::App免责声明:我是gollum-auth :-)
https://stackoverflow.com/questions/40690778
复制相似问题