Giter Club home page Giter Club logo

aws4's Introduction

This gem signs HTTP headers with the AWS4 signature for use with Amazon’s AWS APIs.

It is designed to be library agnostic.

Usage

# create a signer
signer = AWS4::Signer.new(
  access_key: "key",
  secret_key: "secret",
  region: "us-east-1"
)

# build request
uri = URI("https://dynamodb.us-east-1.amazonaws.com/")
headers = {
  "Date" => "Mon, 09 Sep 2011 23:36:00 GMT",
  "Content-Type" => "application/json; charset=utf8"
}
body="{}"

# sign headers
headers = signer.sign("POST", uri, headers, body)

Test

bundle install && rake test

License

The MIT License (MIT)

Copyright (c) 2013 Brandon Keene

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

aws4's People

Contributors

begault avatar cmdrkeene avatar dannyben avatar laurilehmijoki avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

aws4's Issues

Missing some code in the gem on the gem server

We are missing the extra service param in AWS4::Signer#sign:

class Signer
  RFC8601BASIC = "%Y%m%dT%H%M%SZ"
  attr_reader :access_key, :secret_key, :region
  attr_reader :date, :method, :uri, :headers, :body, :service

  def initialize(config)
    @access_key = config[:access_key] || config["access_key"]
    @secret_key = config[:secret_key] || config["secret_key"]
    @region = config[:region] || config["region"]
  end

  def sign(method, uri, headers, body, debug = false)
    @method = method.upcase
    @uri = uri
    @headers = headers
    @body = body
    @service = @uri.host.split(".", 2)[0]
    date_header = headers["Date"] || headers["DATE"] || headers["date"]
    @date = (date_header ? Time.parse(date_header) : Time.now).utc.strftime(RFC8601BASIC)
    dump if debug
    signed = headers.dup
    signed['Authorization'] = authorization(headers)
    signed
  end

Can we upload the latest copy of version 0.0.2?

New release

Hi @cmdrkeene,

Are you planing on releasing soon? The current release (0.0.2) is from May 17th 2013 and does not include the PRs merged this year.

Thanks for working on the gem!

parameter names not sorted by character code generates invalid signature

hello thank you for providing this code. i have a suggestion for an improvement based upon an issue i just encountered.

when given the following example URI:

https://host.whatever/procedures?start=1496880000000&end=1496966400000

the aws4 gem will make an invalid signature because, according to the AWS docs for generating canoncial requests:

Sort the parameter names by character code point in ascending order. For example, a parameter name that begins with the uppercase letter F precedes a parameter name that begins with a lowercase letter b.

so, when i change the above URI to the following:

https://host.whatever/procedures?end=1496966400000&start=1496880000000

the aws4 gem will make a valid signature, because the parameter names are ordered as shown in the documentation.

not sure when i can get around to submitting a pull request to fix this. regardless, i hope this will help someone else out there.

thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.