Skip to content

Instantly share code, notes, and snippets.

View coderliu's full-sized avatar
🏠
Working from home

Ergo Lau coderliu

🏠
Working from home
  • Xiamen, Fujian, China
View GitHub Profile
@coderliu
coderliu / aliyun_oss_callbackable.rb
Created May 17, 2018 08:56
a ActiveSupport Concern for Aliyun OSS callback to save your time
module AliyunOssCallbackable
extend ActiveSupport::Concern
PUB_KEY_URL_PREFIX = 'http://gosspublic.alicdn.com/'
PUB_KEY_URL_PREFIX_S = 'https://gosspublic.alicdn.com/'
def authenticate_aliyun!
pub_key_url = Base64.decode64(request.headers['x-oss-pub-key-url'])
pub_key = get_public_key(pub_key_url)
rsa = OpenSSL::PKey::RSA.new(pub_key)
@coderliu
coderliu / scoped_policies.rb
Last active July 2, 2020 15:50
Rails controller concerns for using pundit with scope of controller
# app/controllers/concerns/scoped_policies
# add `include ScopedPolicies` to your scoped base controller such as Api::BaseController
module ScopedPolicies
extend ActiveSupport::Concern
included do
helper_method :authorize
helper_method :policy_scope
end