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

Added NameIdPolicy support #105

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

zealot128
Copy link

Until now, users can already supply multiple name formats given in the readme (persistent, transient etc) but it seems they were never used and the auth request will always just use the first name (method "chosen" by the NameIdFormatter always returned the first)

This PR fixes this by passing down the requested NameIdFormat from the request.

  • If the saml client requests a specific format, then we can respond the name id with that format
  • Keeping old behavior if no nameidpolicy passed down or none matching

Use case:

e.g. if a client app is configured Omniauth-saml:

# config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :saml, 
    issuer: '...', 
    # ....
    name_identifier_format: "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent",

And our IDP app is configured like this:

SamlIdp.configure do |config|
  config.name_id.formats = {
      email_address: ->(user) { user.email },
      persistent: ->(user) { user.login_name },
    }

the old behavior was, the we always got the email-address field as "uid". After this PR we get the correct name id from omniauth.

# client-app: Omniauth Callback controller e.g. /auth/saml/callback
class OmniauthCallbackController < ApplicationController
    skip_before_action :verify_authenticity_token
    def login
       request.env['omniauth.auth']['uid'] # will be == user.login_name, not user.email
    end
end

* If the saml client requests a specific format, then we can respond the name id with that format
* Keeping old behavior if no nameidpolicy passed down or none given
Copy link
Collaborator

@jphenow jphenow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, Apparently I had a question months ago but forgot that I had to submit the review.

@@ -139,7 +141,7 @@ def name_id_getter
private :name_id_getter

def name_id_format
@name_id_format ||= NameIdFormatter.new(config.name_id.formats).chosen
@name_id_format ||= NameIdFormatter.new(config.name_id.formats).chosen(name_id_policy)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can the policy be passed in at initialization or is there a good reason to pass it in at time of calling chosen?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants