Sha256: c0ad1ade853d4b9d225e01843d48aece417fd858eab5074cd64ad3fa8d37b741
Contents?: true
Size: 934 Bytes
Versions: 1
Compression:
Stored size: 934 Bytes
Contents
require "ostruct" require "json" require_relative "authz_jurnal_client/version" module AuthzJurnalClient class Error < StandardError; end class UserRoles class << self attr_accessor :headers def call(req) @headers = r_headers(req.headers) return get_errors({ errors: { messages: "You are not authorized to access!" } }) if @headers == {} || @headers['Authorization'].nil? if @headers['X-Consumer-Roles'].nil? return get_errors({ errors: { messages: "Roles not found on headers!" } }) end roles end private def roles @headers['X-Consumer-Roles'].split(',').collect { |e| e.strip } end def r_headers(h) h.is_a?(Hash) ? JSON.parse(h.to_json) : h end def get_errors(e) data = e.is_a?(Hash) ? e : eval(e) JSON.parse(data.to_json, object_class: OpenStruct) end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
authz_jurnal_client-0.0.9 | lib/authz_jurnal_client.rb |