url_signer:一个简单的宝石来签署网址

  • a9_707245
    了解作者
  • 11.7KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-15 00:45
    上传日期
网址签名者 快速生成和验证签名的 url。 安装 将此行添加到应用程序的 Gemfile 中: gem 'url_signer' 然后执行: $ bundle 或者自己安装: $ gem install url_signer 用法 注意:对于最有用的方法有 rdoc 格式的注释,因此在 shell 中运行rdoc将使您深入了解可用选项。 还会生成它的 HTML 版本。 网址签名 要将 URL 转换为签名 url,请将其传递给UrlSigner.sign ,将URI实例的字符串传递给它。 # generate a new URI instance with `signature` param populated signed_url = UrlSigner . sign ( 'http://google.fr?q=test' , key : 'mykey' ) 返回值s
url_signer-master.zip
  • url_signer-master
  • .travis.yml
    40B
  • Rakefile
    151B
  • url_signer.gemspec
    1KB
  • Gemfile
    93B
  • spec
  • signer_spec.rb
    1KB
  • uri_spec.rb
    476B
  • base_spec.rb
    2.1KB
  • url_signer_spec.rb
    829B
  • verifier_spec.rb
    1.2KB
  • spec_helper.rb
    117B
  • .gitignore
    118B
  • lib
  • url_signer.rb
    2KB
  • url_signer
  • base.rb
    1.3KB
  • rails.rb
    2.6KB
  • verifier.rb
    633B
  • signer.rb
    403B
  • version.rb
    39B
  • uri.rb
    630B
  • README.md
    3.2KB
  • LICENSE.txt
    1KB
内容介绍
# UrlSigner [![Gem Version](https://badge.fury.io/rb/url_signer.svg)](http://badge.fury.io/rb/url_signer) [![Build Status](https://travis-ci.org/ushu/url_signer.svg?branch=master)](https://travis-ci.org/ushu/url_signer) [![Code Climate](https://codeclimate.com/github/ushu/url_signer/badges/gpa.svg)](https://codeclimate.com/github/ushu/url_signer) Quickly generate and verify signed urls. ## Installation Add this line to your application's Gemfile: ```ruby gem 'url_signer' ``` And then execute: $ bundle Or install it yourself as: $ gem install url_signer ## Usage *Note*: There are rdoc-formatted comments on the most useful methods, so running `rdoc` in the shell will give you insights on the available options. [Rubygems](https://rubygems.org/) also generate a HTML version of it [here](http://www.rubydoc.info/gems/url_signer). ### URL signing To convert a URL into a signed url, pass it to `UrlSigner.sign`, passing it either a string of an instance of `URI`. ```ruby # generate a new URI instance with `signature` param populated signed_url = UrlSigner.sign('http://google.fr?q=test', key: 'mykey') ``` the returned value `signed_url` is an instance of `URI`. ### URL verification Given a signed URL, you can check its authenticity by calling `UrlSigner.valid?` on it: ```ruby # verify url validity for a given URI instance UrlSigner.valid?(signed_url, key: 'mykey') # => true ``` ### Helper methods on URI The gem adds the `signed` helper method to <tt>URI</tt>, that returns a new signed version of the url: ```ruby url = URI.parse('http://google.fr') signed_url = url.signed(key: 'test') ``` ## Rails integration When using `Rails`, a set of helpers are added to `ActionController::Base`: ```ruby class MyController < ActionController::Base # Will trigger the check on the request url before_action :verify_signature!, only: secure_action def get_signed_url @signed_url = sign_url(my_controller_secure_action_url) # Template will link to @signed_url end def secure_action # This method is only accessible with a signed url end end ``` Note that the `sign_url` helper can also be used as a view helper: ```erb <%= link_to 'Super secure action', sign_url(my_controller_secure_action_url) %> ``` The key and hash method used in `sign_url` and `verify_signature!` are provided through `Rails.configuration.url_signer`, which default to: ```ruby # defaults values: Rails.configuration.url_signer.key = ENV['URL_SIGNING_KEY'] Rails.configuration.url_signer.hash_method = Digest::SHA1 ``` Note that provided env `URL_SIGNING_KEY` environment variable is usually enough to get a working URL signing environment. ## TODO - [ ] Add an option to choose the param name: it is currently set to `signature` - [ ] Allow to customize the signing process by selecting with parts of the URL to include (for eg. allow to sign only considering path and not domain etc.) - [ ] Write tests for the Rails integration - [ ] Improve docs ## Contributing 1. Fork it ( https://github.com/ushu/url_signer/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create a new Pull Request
评论
    相关推荐
    • swim.html:http
      swim.html 来源
    • Html2Xaml:http的分叉
      Html2Xaml 这不是将 html 转换为 xaml 的好方法,我认为最好将其转换为列表,并通过 ListView 显示内容
    • html-redirect:生成 HTML 重定向页面
      htmlRedirect ( 'http://example.com' ) . pipe ( fs . createWriteStream ( 'example1.html' ) ) ; 示例1.html: <!DOCTYPE html > < html > < head > < title > (redirect) </ ...
    • Lingulo-Responsive-Tutorial:httpHTML5自适应网站教程
      语言响应式教程 HTML5自适应网站教程, 此HTML5网站是Christoph Anastasiades创建HTML5 / CSS3教程的一部分( )随意使用用于您的个人或商业项目...为了最大程度地减少HTTP请求的数量,请将所有CSS文件合并为一个文件
    • Cryptoquips:这个简单的应用程序从http解析html
      密码学 这个简单的应用程序解析html,并在卡视图中显示列出的Cryptoquip图像。
    • Lightweight C-HTTP & HTML Wrapper:轻量级的C-HTTPHTML包装器-开源
      它是一个C-HTTPHTML包装器,用于自动处理Web数据。 一些示例是:-接收网站以检查其是否正常运行-从例如下载您的个人数据。 网上银行,帐单...-处理网站中包含的数据,例如天气数据-接收大量数据,尤其是对网站...
    • slackify-html
      slackify-htmlhtml转换为 用法示例: var slackify = require('slackify-html'); var text = slackify('this <a>link</a> is <b>important</b>');...// text variable contains 'this <http> is *important*'
    • HTML5-Examples:httpHTML 5示例-html source website
      HTML5-示例 HTML 5示例。 版权所有2012:SKJ Technologies Private Ltd 这些示例已根据“知识共享署名-相同的ShareAlike 3.0未移植”(CC BY-SA 3.0)许可证进行共享。 有关CC BY-SA 3.0许可证的更多详细信息,请...
    • html定时抓取程序
      利用http协议,定时抓取指定网页内容,保存为.htm文件的程序;利用http协议,定时抓取指定网页内容,保存为.htm文件的程序;
    • html日期控件
      http://hiyu2218.bokele.com/?CH=6441