forked from doorkeeper-gem/doorkeeper-openid_connect
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: Respect scope grants in UserInfo response
- Support a :scope parameter when defining claims - Remove the Models namespace since these aren't Rails models
- Loading branch information
Showing
26 changed files
with
273 additions
and
181 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Doorkeeper | ||
module OpenidConnect | ||
module Claims | ||
class AggregatedClaim < Claim | ||
attr_accessor :jwt | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module Doorkeeper | ||
module OpenidConnect | ||
module Claims | ||
class Claim | ||
attr_accessor :name, :scope | ||
|
||
# http://openid.net/specs/openid-connect-core-1_0.html#StandardClaims | ||
# http://openid.net/specs/openid-connect-core-1_0.html#ScopeClaims | ||
STANDARD_CLAIMS = { | ||
profile: %w[ | ||
name family_name given_name middle_name nickname preferred_username | ||
profile picture website gender birthdate zoneinfo locale updated_at | ||
], | ||
email: %w[ email email_verified ], | ||
address: %w[ address ], | ||
phone: %w[ phone_number phone_number_verified ], | ||
} | ||
|
||
def initialize(options = {}) | ||
@name = options[:name] | ||
@scope = options[:scope] | ||
|
||
# use default scope for Standard Claims | ||
@scope ||= STANDARD_CLAIMS.find do |_scope, claims| | ||
claims.include? @name | ||
end.try(:first) | ||
|
||
# use profile scope as default fallback | ||
@scope ||= :profile | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
module Doorkeeper | ||
module OpenidConnect | ||
module Claims | ||
class DistributedClaim < Claim | ||
attr_accessor :endpoint, :access_token | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
module Doorkeeper | ||
module OpenidConnect | ||
module Claims | ||
class NormalClaim < Claim | ||
attr_reader :generator | ||
|
||
def initialize(options = {}) | ||
super(options) | ||
@generator = options[:generator] | ||
end | ||
|
||
def type | ||
:normal | ||
end | ||
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,62 @@ | ||
module Doorkeeper | ||
module OpenidConnect | ||
class IdToken | ||
include ActiveModel::Validations | ||
|
||
attr_reader :nonce | ||
|
||
def initialize(access_token, nonce = nil) | ||
@access_token = access_token | ||
@nonce = nonce | ||
@resource_owner = access_token.instance_eval(&Doorkeeper::OpenidConnect.configuration.resource_owner_from_access_token) | ||
@issued_at = Time.now | ||
end | ||
|
||
def claims | ||
{ | ||
iss: issuer, | ||
sub: subject, | ||
aud: audience, | ||
exp: expiration, | ||
iat: issued_at, | ||
nonce: nonce, | ||
auth_time: auth_time, | ||
} | ||
end | ||
|
||
def as_json(*_) | ||
claims.reject { |_, value| value.blank? } | ||
end | ||
|
||
def as_jws_token | ||
JSON::JWT.new(as_json).sign(Doorkeeper::OpenidConnect.signing_key).to_s | ||
end | ||
|
||
private | ||
|
||
def issuer | ||
Doorkeeper::OpenidConnect.configuration.issuer | ||
end | ||
|
||
def subject | ||
@resource_owner.instance_eval(&Doorkeeper::OpenidConnect.configuration.subject).to_s | ||
end | ||
|
||
def audience | ||
@access_token.application.uid | ||
end | ||
|
||
def expiration | ||
(@issued_at.utc + Doorkeeper::OpenidConnect.configuration.expiration).to_i | ||
end | ||
|
||
def issued_at | ||
@issued_at.utc.to_i | ||
end | ||
|
||
def auth_time | ||
@resource_owner.instance_eval(&Doorkeeper::OpenidConnect.configuration.auth_time_from_resource_owner).try(:to_i) | ||
end | ||
end | ||
end | ||
end |
11 changes: 0 additions & 11 deletions
11
lib/doorkeeper/openid_connect/models/claims/aggregated_claim.rb
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
lib/doorkeeper/openid_connect/models/claims/distributed_claim.rb
This file was deleted.
Oops, something went wrong.
24 changes: 0 additions & 24 deletions
24
lib/doorkeeper/openid_connect/models/claims/normal_claim.rb
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
Oops, something went wrong.