在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):o2web/graphql-auth开源软件地址(OpenSource Url):https://github.com/o2web/graphql-auth开源编程语言(OpenSource Language):Ruby 91.3%开源软件介绍(OpenSource Introduction):GraphQL AuthThis gem provides an authentication mechanism on a GraphQL API. It use JSON Web Token (JWT) and Devise logic. InstallationAdd this line to your application's Gemfile: gem 'graphql-auth' And then execute:
Or install it yourself as:
Then run the installer to create
Make sure to read all configurations present inside the file and fill them with your own configs. Devise gemUse Devise with a User model and skip all route Rails.application.routes.draw do
devise_for :users, skip: :all
end UsageMake 'JWT_SECRET_KEY' and 'APP_URL' available to ENV
Make sure the Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*',
headers: %w(Authorization Expires RefreshToken),
methods: :any,
expose: %w(Authorization Expires RefreshToken),
max_age: 600
end
end Make sure to include class GraphqlController < ActionController::API
include Graphql::AuthHelper
def execute
variables = ensure_hash(params[:variables])
query = params[:query]
operation_name = params[:operationName]
result = ::GraphqlSchema.execute(query, variables: variables, context: context, operation_name: operation_name)
render json: result
... Make sure to implement class Types::MutationType < Types::BaseObject
implements ::Types::GraphqlAuth
end CustomizationIf you can to customize any mutation, make sure to update the configurations GraphQL::Auth.configure do |config|
# config.token_lifespan = 4.hours
# config.jwt_secret_key = ENV['JWT_SECRET_KEY']
# config.app_url = ENV['APP_URL']
# config.user_type = '::Types::Auth::User'
# Devise allowed actions
# Don't forget to enable the lockable setting in your Devise user model if you plan on using the lock_account feature
# config.allow_sign_up = true
# config.allow_lock_account = false
# config.allow_unlock_account = false
# Allow custom mutations for signup and update account
# config.sign_up_mutation = '::Mutations::Auth::SignUp'
# config.update_account_mutation = '::Mutations::Auth::UpdateAccount'
end DevelopmentAfter checking out the repo, run To install this gem onto your local machine, run ContributingBug reports and pull requests are welcome on GitHub at https://github.com/o2web/graphql-auth. 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. LicenseThe gem is available as open source under the terms of the MIT License. Code of ConductEveryone interacting in the GraphQL Auth project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论