Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add scope config option #50

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions lib/keycloak_oauth.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require_relative 'keycloak_oauth/version'
require_relative 'keycloak_oauth/configuration'
require_relative 'keycloak_oauth/connection'
require_relative 'keycloak_oauth/engine'
require_relative "keycloak_oauth/version"
require_relative "keycloak_oauth/configuration"
require_relative "keycloak_oauth/connection"
require_relative "keycloak_oauth/engine"

module KeycloakOauth
def self.configure
Expand All @@ -18,7 +18,8 @@ def self.connection
realm: configuration.realm,
client_id: configuration.client_id,
client_secret: configuration.client_secret,
callback_module: configuration.callback_module
callback_module: configuration.callback_module,
scope: configuration.scope,
)
end
end
4 changes: 2 additions & 2 deletions lib/keycloak_oauth/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
require 'singleton'
require "singleton"

module KeycloakOauth
class Configuration
include Singleton

attr_accessor :auth_url, :realm, :client_id, :client_secret, :callback_module
attr_accessor :auth_url, :realm, :client_id, :client_secret, :callback_module, :scope
end
end
9 changes: 5 additions & 4 deletions lib/keycloak_oauth/connection.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
require_relative 'endpoints'
require_relative "endpoints"

module KeycloakOauth
class Connection
include KeycloakOauth::Endpoints

attr_reader :auth_url, :realm, :client_id, :client_secret, :callback_module
attr_reader :auth_url, :realm, :client_id, :client_secret, :callback_module, :scope

def initialize(auth_url:, realm:, client_id:, client_secret:, callback_module: nil)
def initialize(auth_url:, realm:, client_id:, client_secret:, callback_module: nil, scope: nil)
@auth_url = auth_url
@realm = realm
@client_id = client_id
@client_secret = client_secret
@callback_module = callback_module
@scope = scope ||= "openid"
end

def get_user_information(access_token:, refresh_token:)
service = KeycloakOauth::UserInfoRetrievalService.new(
access_token: access_token,
refresh_token: refresh_token
refresh_token: refresh_token,
)
service.perform
service.parsed_response_body
Expand Down
3 changes: 2 additions & 1 deletion lib/keycloak_oauth/endpoints.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
module KeycloakOauth
module Endpoints
DEFAULT_RESPONSE_TYPE = 'code'.freeze
DEFAULT_RESPONSE_TYPE = "code".freeze

def authorization_endpoint(options: {})
endpoint = "#{auth_url}/realms/#{realm}/protocol/openid-connect/auth?client_id=#{client_id}"
endpoint += "&response_type=#{options[:response_type] || DEFAULT_RESPONSE_TYPE}"
endpoint += "&redirect_uri=#{options[:redirect_uri]}" if options[:redirect_uri].present?
endpoint += "&scope=#{scope}"
endpoint
end

Expand Down