Skip to content

validating jwt signature from alma#42

Draft
davezuckerman wants to merge 3 commits intomainfrom
AP-634-alma-jwt
Draft

validating jwt signature from alma#42
davezuckerman wants to merge 3 commits intomainfrom
AP-634-alma-jwt

Conversation

@davezuckerman
Copy link
Copy Markdown
Contributor

No description provided.

Copy link
Copy Markdown
Contributor

@jason-raitz jason-raitz left a comment

Choose a reason for hiding this comment

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

lgtm.

Copy link
Copy Markdown
Member

@anarchivist anarchivist left a comment

Choose a reason for hiding this comment

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

I think this needs some refactoring - we should look at using ruby-jwt's native methods here rather than rolling our own.

Comment thread app/controllers/concerns/alma_jwt_validator.rb
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Similarly, there's a lot in this file that seems to duplicate what's in JWT::JWK's methods here.

Copy link
Copy Markdown
Member

@danschmidt5189 danschmidt5189 left a comment

Choose a reason for hiding this comment

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

I have a few nits but they're nothing major (see comments).

One bigger picture question is whether to implement this using an AlmaJwtValidator module (as you've done) or an AlmaJwt class. The benefit of the class is that it could naturally encapsulate the accessor method you implicitly need (username -> alma_id). Not a blocker, but something to think about from an implementation / code style perspective.

require 'json'

module AlmaJwtValidator
JWKS_URL = 'https://api-na.hosted.exlibrisgroup.com/auth/01UCS_BER/jwks.json'.freeze
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does the sandbox publish a different URL? If so we'd need to be able to inject this (e.g. via ENV).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

As we noticed when pairing, the actual issuer is Prima. From our testing:

# Get a Ruby shell with jwt installed...
$ docker run --rm -it ruby:3 bash -c 'gem install pry; gem install jwt; exec pry'

# Login to Alma, then visit the fees link from your account page.
# Extract the jwt from the URL in the Framework redirect and decode it.
require 'jwt'
jwt = "{copy from URL}"
JWT.decode(jwt, nil, false)


module AlmaJwtValidator
JWKS_URL = 'https://api-na.hosted.exlibrisgroup.com/auth/01UCS_BER/jwks.json'.freeze
EXPECTED_ISS = 'https://api-na.hosted.exlibrisgroup.com/auth/01UCS_BER'.freeze
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ditto for this.

Comment thread app/controllers/concerns/alma_jwt_validator.rb Outdated
Comment thread app/controllers/concerns/alma_jwt_validator.rb
jwks: jwk_set
}

JWT.decode(token, nil, true, options)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I suppose this wasn't clear from my earlier comment, but I'm curious about why we're using JWT.decode instead of instantiating JWT::EncodedToken and using its methods.

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.

4 participants