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 openid connect support using doorkeeper-openid_connect gem #4226

Merged
merged 6 commits into from
Oct 3, 2023

Conversation

milan-cvetkovic
Copy link
Contributor

...as discussed in Issue 507 and described by @mmd-osm.

To activate, set the value of doorkeeper_signing_key to pem of the RSA private key.

Allows using openstreetmap as an identity provider.

Adds openid scope to OAuth2 authorizations, required to login to OSM.

Currently, the only claims returned are sub and preferred_username.

Copy link
Member

@tomhughes tomhughes left a comment

Choose a reason for hiding this comment

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

This is just an initial review of obvious things as I haven't looked at any of the details of the gem and how it works.

db/migrate/20230830115221_add_openid_scope.rb Outdated Show resolved Hide resolved
config/locales/doorkeeper_openid_connect.en.yml Outdated Show resolved Hide resolved
Gemfile Outdated Show resolved Hide resolved
@milan-cvetkovic
Copy link
Contributor Author

This is just an initial review of obvious things as I haven't looked at any of the details of the gem and how it works.

Thanks for the quick review! I will look into addressing your comments.

@tomhughes
Copy link
Member

I reran the actions as they failed due to some github issue and the rubocop run has now picked up a bunch more things.

@tomhughes
Copy link
Member

I think from https://github.com/doorkeeper-gem/doorkeeper-openid_connect#internationalization-i18n that they will actually be found in the gem - the installer just added a copy of them so they could be customised.

That said it may be worth adding them so they can be translated - the main doorkeeper ones don't need to be as the doorkeeper-i18n gem does it.

Copy link
Member

@tomhughes tomhughes left a comment

Choose a reason for hiding this comment

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

Some more review comments based on my initial reading of the specification and the gem documentation.

I think we need to understand exactly the interaction between claims and scopes and which scopes we need to enable the different claims and I still need to read up on discovery though I'm not sure if that matters to us.

We also need to think about whether we want to make this generally available or whether it should be privileged and just to support internal use cases like the wiki.

config/initializers/doorkeeper_openid_connect.rb Outdated Show resolved Hide resolved
config/initializers/doorkeeper_openid_connect.rb Outdated Show resolved Hide resolved
config/initializers/doorkeeper_openid_connect.rb Outdated Show resolved Hide resolved
config/initializers/doorkeeper_openid_connect.rb Outdated Show resolved Hide resolved
config/initializers/doorkeeper_openid_connect.rb Outdated Show resolved Hide resolved
lib/oauth.rb Outdated Show resolved Hide resolved
@milan-cvetkovic milan-cvetkovic force-pushed the openid-connect branch 4 times, most recently from a4653bc to 33e45d0 Compare September 6, 2023 12:59
@milan-cvetkovic
Copy link
Contributor Author

milan-cvetkovic commented Sep 6, 2023

I added email claim to read_email privileged scope.

ID_TOKEN and userinfo response now contain sub, preferred_name, and email claims.

Please let me know if I should create separate profile claim, and what to put in it.

@tomhughes
Copy link
Member

The profile claim is probably not important for us, at least for the wiki. If we were to do it then I imagine /user/display_name would be the place to point it.

@milan-cvetkovic
Copy link
Contributor Author

milan-cvetkovic commented Sep 7, 2023

EDIT: this modification has been reverted.

I added a separate profile scope with some additional claims - normally part of public information and easily accessible from users table. Moved preferred_username to profile scope.

ID_TOKEN contains:

  • sub (OSM user id)
  • preferred_username (OSM display name)
  • email
  • email_verified

/oauth2/userinfo endpoint returns:

  • sub
  • preferred_username
  • email
  • email_verififed
  • profile - profile url
  • description - from profile, if available
  • contributor_terms_agreed (boolean)
  • changesets_count
  • traces_count

Only claims appropriate for the scope are returned:

  • email and email_verified only for privileged users having read_email scope
  • sub claimis the only field returned with openid scope, The remaining claims are in profile scope.

@milan-cvetkovic
Copy link
Contributor Author

@tomhughes

I think we need to understand exactly the interaction between claims and scopes and which scopes we need to enable the different claims and I still need to read up on discovery though I'm not sure if that matters to us.

We also need to think about whether we want to make this generally available or whether it should be privileged and just to support internal use cases like the wiki.

The well-known endpoints (discovery) are required for openid connect to work, at least using doorkeeper-openid_connect plugin. In particular, the openid-configuration endpoint is queried for token_endpoint, jwksuri_endpoint and userinfo_endpont used in later phases.

Any 3rd party app using OSM as ID provider would require at least a persistent value correlated to userid, which would be returned as a sub field in id_token.

@tomhughes
Copy link
Member

Sure I realise we need to provide an ID but I didn't realise discovery was essential since it seemed to be a separate component but if we need it then fine.

One thing we do need to think about is how to test this...

@milan-cvetkovic
Copy link
Contributor Author

I tested most of the flow manually.

I did try to write automated tests, but was not successful. The most I got is to verify the existence of discovery endpoints.

I am not too familiar with the testing framework, but the problems started when initiating authorization, the test was not able to access the endpoints reported by openid-configuration, as if the routes were not present.

@milan-cvetkovic
Copy link
Contributor Author

milan-cvetkovic commented Sep 15, 2023

@tomhughes I have added an openid connect test to oauth2 integration test.

Are there more changes to this PR that you had in mind?

config/settings.yml Show resolved Hide resolved
config/settings/test.yml Outdated Show resolved Hide resolved
db/structure.sql Outdated Show resolved Hide resolved
db/structure.sql Outdated Show resolved Hide resolved
test/integration/oauth2_test.rb Outdated Show resolved Hide resolved
test/integration/oauth2_test.rb Show resolved Hide resolved
test/integration/oauth2_test.rb Outdated Show resolved Hide resolved
@tomhughes
Copy link
Member

Are there more changes to this PR that you had in mind?

I've done a new review which is mostly about the test.

Other than that it's on the agenda for this weeks operations call to discuss whether we want to make this globally available or keep it for internal use. I had hoped to have that discussion on the last call but we ran out of time.

@milan-cvetkovic milan-cvetkovic force-pushed the openid-connect branch 5 times, most recently from 43e03c2 to c9f0582 Compare September 21, 2023 11:09
@milan-cvetkovic
Copy link
Contributor Author

@tomhughes Any updates with this PR?

After executing:
rails generate doorkeeper:openid_connect:install
rails generate doorkeeper:openid_connect:install

Split migration script to 2 to avoid deadlock.
... as discussed in [Issue 507](openstreetmap/operations#507)
and described by @mmd-osm.

To activate, set the value of `doorkeeper_signing_key` to RSA private key.

Allows using openstreetmap as an identity provider.

Adds `openid` scope to OAuth2 authorizations, required to login to OSM.

Currently, the only claims returned are:
 - "openid" scope: "sub" and "preferred_username"
 - "read_email" scope: "email"
@tomhughes tomhughes merged commit c8fc221 into openstreetmap:master Oct 3, 2023
@tomhughes
Copy link
Member

I made a few minor textual cleanups and merged this.

As it involves a migration I'm going to wait until the database backup which is currently running completes (which should be tomorrow) before deploying it.

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.

3 participants