首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何配置Gollum-wiki以允许基本身份验证并使用用户名进行git提交

如何配置Gollum-wiki以允许基本身份验证并使用用户名进行git提交
EN

Stack Overflow用户
提问于 2016-11-19 08:29:43
回答 2查看 2.3K关注 0票数 3

我试图为gollum配置基本的http身份验证,但我希望登录用户名用于git提交。

我已经修改了config.ru,以便基本身份验证工作,现在我只需要弄清楚如何实现以下功能:

代码语言:javascript
复制
session['gollum.author'] => "%s" % loggedIn

然后我可以去掉“约翰·史密斯”的绳子。

顺便说一句--请原谅这个愚蠢的问题,我以前从未碰过Ruby,现在已经很晚了。

代码语言:javascript
复制
#!/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命名空间中,因此不能通过身份验证方法直接设置它:

代码语言:javascript
复制
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

我也试过:

代码语言:javascript
复制
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)
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2016-11-19 19:03:15

这里有一个解决方案,它允许您定义一系列用户,启用基本的http身份验证,并使用登录的用户名进行fit提交。

代码语言:javascript
复制
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
票数 5
EN

Stack Overflow用户

发布于 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 (取自项目的自述文件):

代码语言:javascript
复制
#!/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 :-)

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40690778

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档