forked from brandnewbox/oidc_provider
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implements basic claims request parameter (Closes brandnewbox#11)
- Loading branch information
Showing
7 changed files
with
206 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,33 @@ | ||
# frozen_string_literal: true | ||
|
||
module OIDCProvider | ||
class Scope | ||
attr_accessor :name, :work | ||
attr_accessor :claims, :name, :work | ||
|
||
def initialize(name, &block) | ||
@name = name | ||
@work = block | ||
|
||
@claims = OIDCProvider.claims_from_scope(self) | ||
inject_claims_to_id_token_if_needed! | ||
end | ||
|
||
private | ||
|
||
# Since the openid_connect gem is limiting the allowed attributes on the | ||
# response classes, this gem declares more optional attributes on the | ||
# OpenIDConnect::ResponseObject::IdToken class. | ||
# | ||
# NOTE : This is done when adding a scope to this gem, so only once at the | ||
# app's boot time when initializing this gem. | ||
# NOTE : Ideally the openid_connect gem should be patched in order to allow | ||
# more claims without this hack. | ||
def inject_claims_to_id_token_if_needed! | ||
missings = @claims - OpenIDConnect::ResponseObject::IdToken.all_attributes | ||
|
||
return if missings.empty? | ||
|
||
OpenIDConnect::ResponseObject::IdToken.attr_optional(*missings) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# frozen_string_literal: true | ||
|
||
module OIDCProvider | ||
class ScopeConfig | ||
attr_accessor :force_claim, :requested_claims, :scope | ||
|
||
def initialize(scope, requested_claims) | ||
@force_claim = {} | ||
@requested_claims = requested_claims | ||
@scope = scope | ||
end | ||
|
||
def add_force_claim(key_value) | ||
raise ArgumentError unless key_value.is_a?(Hash) | ||
|
||
# Only stores keys where the value is not `nil` thanks to the `.compact` | ||
# method. | ||
@force_claim.merge!(key_value.compact) | ||
end | ||
|
||
def name | ||
@scope.name | ||
end | ||
end | ||
end |