
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
GraphqlAuthorizer is built to provide simple access authorization in Graphql
Endpoints by encrypting Access Key
and request Timestamp
.
Add this line to your application's Gemfile:
gem 'graphql_authorizer'
# or with git source
gem "graphql_authorizer", git: "git@bitbucket.org:gorated/graphql-authorizer.git"
And then execute:
$ bundle
Or install it yourself as:
$ gem install graphql_authorizer
run generator:
$ rails g graphql_authorizer:install
This will generate initializer configuration files for:
Add Rack Attack in application.rb:
# In config/application.rb
config.middleware.use Rack::Attack
note: Rack Attack
initializer file contains basic configurations to allow
,
block
and throttle
client's access based on defined conditions.
For more configuration options please check rack-attack
note: you need to supply shared access key for client
and application
in
initializers/graphql_authorizer.rb
GraphQLAuthorizer provides helper methods for validating if the request is
valid, by initializing the GraphQLAuthorization::Request
class and providing
timestamp
and signature
as arguments.
timestamp = Time.zone.now.to_i.to_s
sig = SecureRandom.hex(8)
request_validator = GraphQLAuthorizer::Request.new(timestamp: timestamp, sig: sig)
request_validator.valid? # returns boolean `true` or `false`
request_validator.erros # returns array of error messages if request validator
returns `false` otherwise returns `nil`
note:
GraphQLAuthorizer use OpenSSL::Digest
and OpenSSL::HMAC
to validate
request by encrypting timestamp
and access_key
.
Client's must provide encrypted signature by encrypting access_key
and
timestamp
upon request.
Sample Client Request Configuration with graphql-client
require "graphql/client"
require "graphql/client/http"
class Queries::SWAPI
# Configure GraphQL endpoint using the basic HTTP network adapter.
endpoint = ENV.fetch("APP_ENDPOINT")
HTTP = GraphQL::Client::HTTP.new(endpoint) do
def headers(context)
# Optionally set any HTTP headers
timestamp = Time.now.to_i.to_s
token = generate_token(timestamp: timestamp)
{
"Request-Signature" => token, # Required for signature validation
"Request-Timestamp" => timestamp, # Required for request timestamp
validation
"Authorization" => context
}
end
def generate_token(timestamp:)
access_key = ENV.fetch("GRAPHQL_ACCESS_KEY")
digest = OpenSSL::Digest.new("sha256")
OpenSSL::HMAC.hexdigest(digest, access_key, timestamp)
end
end
Schema = GraphQL::Client.load_schema("schema.json")
Client = GraphQL::Client.new(schema: Schema, execute: HTTP)
end
After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install
. To release a new version, update the version number in version.rb
, and then run bundle exec rake release
, which will create a git tag for the version, push git commits and tags, and push the .gem
file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/GraphQL_Authorizer. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the GraphQLAuthorizer project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.
FAQs
Unknown package
We found that graphql_authorizer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.