Skip to content
This repository was archived by the owner on Jun 12, 2021. It is now read-only.

Conversation

@angelakis
Copy link
Contributor

@angelakis angelakis commented Jun 16, 2020

Update:
We decided to refactor token coop based on the by_grant_type branch. Check #59 (comment) for more info.

Original Message:
This is a pull request to implement token exchange a.k.a. RFC 8693.

The implementation will not be as straightforward as I first hoped it would be, as token exchange is an extension grant type used in the token endpoint.

Currently implemented token and tokencoop endpoints, do not have an easy way to add/configure new grant_types so I think we should refactor one of those two.

TokenCoop was selected to be refactored but we could in the future
just keep the new version instead of having both Token and the new
configurable/extendable TokenCoop.

I think it would be a good idea to use grant_types_supported as a configuration option to figure out what grant types the endpoint should support.

As I previously mentioned, this is still a work in progress and the actual token exchange code has not yet been implemented. RFC 8693 is broad so its implementation will need a discussion too.

Any feedback welcome.

@angelakis angelakis force-pushed the feature-token-exchange branch from 3919d57 to 2f85f83 Compare June 17, 2020 13:19
grant_type not in self.token_grant_types
or grant_type not in grant_types_supported
):
raise ProcessError("Invalid grant type")
Copy link
Contributor

Choose a reason for hiding this comment

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

Add the grant_type value to the exception?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes


return request

def _token_exchange_post_parse_request(self, request, client_id="", **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

We could override the parse_request method, add a request_cls param to override self.request_cls and provide the proper one depending on the grant_type. This way we can get rid of *_post_parse_request

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather add a get_request_class() method.

elif grant_type == "urn:ietf:params:oauth:grant-type:token-exchange":
return self._token_exchange_post_parse_request(request, client_id, **kwargs)
else:
raise ProcessError("Invalid grant type")
Copy link
Contributor

Choose a reason for hiding this comment

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

Add the grant_type value to the exception?

Copy link
Contributor

Choose a reason for hiding this comment

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

yes

response_args = self._refresh_access_token(request, **kwargs)
elif grant_type == "urn:ietf:params:oauth:grant-type:token-exchange":
logger.debug("Token Exchange Request")
response_args = self._token_exchange(request, **kwargs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this if/elif/elif to separate function?

@rohe
Copy link
Contributor

rohe commented Jun 24, 2020

Have a look at https://github.com/IdentityPython/oidcendpoint/blob/by_grant_type/src/oidcendpoint/oidc/token_coop.py
I'd rather do it that way.
Now, what you see there is just a first iteration. It should of course be configurable.
But you can see the layout.

@rohe
Copy link
Contributor

rohe commented Jun 25, 2020

I've even added a test based on an example in the RFC.
It's extremely crude but it works :-)

@rohe
Copy link
Contributor

rohe commented Jun 25, 2020

And yes, I think we should get rid of Token and only keep TokenCoop.
Once we've done that we should probably rename TokenCoop to Token.

@angelakis angelakis force-pushed the feature-token-exchange branch from 2f85f83 to a1f2199 Compare September 9, 2020 15:42
@angelakis
Copy link
Contributor Author

We decided to use @rohe's by_grant_type branch and work on that to implement a simple Token Exchange functionality.

I believe that our first goal should be to support exchanging access tokens for new access tokens with (the same or) altered scopes.

In that regard I have just pushed the current implementation which seems to work.

There's one simple change concerning by_grant_type and its configuration:

The user can now set the usual grant types to have a default                  
configuration and class, without the need to set the oidcendpoint             
class path. This can be done by setting a value of "default" or               
None (no value in yaml dict).

There are multiple issues right now and the main one is probably how session works, and its dependency on state. We should discuss a way forward concerning that.

Tests are also missing currently.

Any other feedback welcome.

@angelakis angelakis changed the base branch from master to develop September 10, 2020 10:06
@angelakis angelakis force-pushed the feature-token-exchange branch 3 times, most recently from 2e4a8d1 to 612dec9 Compare September 10, 2020 15:20
@nsklikas
Copy link
Contributor

Can you clean up the commits a little bit? Also it seems that there are extra changes in this PR that are not related to token exchange.

_cinfo = endpoint_context.cdb[client_id]
if isinstance(_cinfo, str):
if not _cinfo in endpoint_context.cdb:
if isinstance(_cinfo, str): # This is if _cinfo is a reference to another client_id
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this needed?

@angelakis angelakis force-pushed the feature-token-exchange branch from 72c95b4 to aa8e983 Compare September 15, 2020 15:30
@angelakis
Copy link
Contributor Author

Pushed multiple tests both for the by-grant-type refactor and token exchange. They try to highlight the functionality we introduce so they will need changes once we decide on the token exchange features (or whether we allow specifying "default" on a grant_type in grant_types_supported).

@angelakis
Copy link
Contributor Author

Can you clean up the commits a little bit? Also it seems that there are extra changes in this PR that are not related to token exchange.

I could remove the isort commits and keep only the parts containing the actual changes in TokenCoop, if that's ok with @rohe. And if we want to do this even better I could split up the grant_types_supported changes and the token exchange ones.

@angelakis angelakis force-pushed the feature-token-exchange branch from aa8e983 to e914eb8 Compare September 17, 2020 11:55
@rohe
Copy link
Contributor

rohe commented Sep 18, 2020

That would be OK with me.

@angelakis angelakis force-pushed the feature-token-exchange branch 2 times, most recently from cee5f8a to 3ecb084 Compare September 24, 2020 13:53
@angelakis angelakis force-pushed the feature-token-exchange branch from 3ecb084 to f13e22d Compare September 24, 2020 15:41
@angelakis
Copy link
Contributor Author

angelakis commented Sep 24, 2020

I cleaned up unrelated changes and then split up the changes in two different branches, creating #88 with the configurable-grant-types parts. So only token exchange related changes should remain here.

This branch is now based on #88 and should be merged after that.

@angelakis angelakis changed the base branch from develop to feature-configurable-grant-types September 24, 2020 15:46
@angelakis angelakis force-pushed the feature-token-exchange branch from f13e22d to 76d1dc6 Compare September 24, 2020 15:53
@angelakis angelakis force-pushed the feature-configurable-grant-types branch from ffee2a9 to ec006ad Compare November 11, 2020 12:52
@angelakis angelakis force-pushed the feature-token-exchange branch from 76d1dc6 to a9a78cf Compare March 11, 2021 12:56
@angelakis angelakis changed the base branch from feature-configurable-grant-types to new_session_handling March 11, 2021 12:58
@angelakis angelakis closed this Mar 11, 2021
@angelakis angelakis force-pushed the feature-token-exchange branch from a9a78cf to a4afb20 Compare March 11, 2021 13:00
@angelakis
Copy link
Contributor Author

Accidentally closed this while trying to push the rebased version to the new session handling. Seeing that this PR has changed a lot since its creation, it may be better to create a new one.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants