Skip to content

feat: No way to fetch external auth refresh token #12787

Closed

Description

@ns-mkusper

Version: v2.9.1+2a2fd70

There is currently no way (or at least not via the Coder CLI or API) to fetch the refresh token for an external auth provider in Coder. I have an external app I am trying to integrate with coder, and its config files require both the access token and the refresh token as a starting point.

A simple solution to me seems to be to add the refresh_token to the GET /workspaceagents/me/external-auth response.

Activity

  1. added
    api
    waiting-for-info
    on Mar 28, 2024
  2. changed the title [-]No way to fetch external auth refresh token[/-] [+]feat: No way to fetch external auth refresh token[/+] on Mar 28, 2024
  3. removed
    waiting-for-info
    on Mar 28, 2024
  4. matifali commented on Mar 28, 2024

    @matifali
    Contributor

    cc: @Emyrk @kylecarbs

    Also related to #12704 where the user is requesting username to be added to coder_external_auth.

  5. kylecarbs commented on Mar 28, 2024

    @kylecarbs
    Member

    @matifali we will do this but should not do the other.

  6. self-assigned this
    on Mar 28, 2024
  7. Emyrk commented on Mar 28, 2024

    @Emyrk
    Member

    I feel like the cli should be able to expose the user external-auth api endpoints.

    The workspace agent endpoint is a bit limiting in the fact it's designed for ASK_PASS style prompting.

    We could add ls and other commands using the user apis.

  8. ns-mkusper commented on Mar 28, 2024

    @ns-mkusper
    Author

    If we could fetch the refresh token via the coder CLI that would be great.

  9. Emyrk commented on Mar 28, 2024

    @Emyrk
    Member

    @kylecarbs brought up a good point. If the refresh token is exposed, it can be used to generate new tokens outside Coder, leaving coder with a stale refresh token.

    What application specifically is requesting this? Maybe there is a workaround on that side?

  10. ns-mkusper commented on Mar 28, 2024

    @ns-mkusper
    Author

    After a bit of research I found we manage a wrapper around an API client library that is essentially the app we're trying to integrate, and that can be easily extended to use the coder CLI to get the updated access token instead of the client library which calls /v1/token itself to refresh tokens.

    That library assumes the oauth2 apps are configured with a PKCE challenge rather than client secrets, so the requests from it to refresh the token itself fail.

    At this point I'm fine to close this issue. I do agree that allowing refresh tokens to be used by other applications would mean a divergence between that app's access tokens and those known by coder, but in cases where they're absolutely needed to integrate an app I'd happily live with it I think. In our case, though, we're happy to live with the workaround we have now.

  11. Emyrk commented on Mar 29, 2024

    @Emyrk
    Member

    If we did expose a refresh_token it would also break any other workspaces that are sharing the same external auth app. Since 1 workspace "takes charge" of it.

    I'm curious why the refresh token is required to auth into your app anyway 🤔. Feels strange, unless it is a clientside app that is managing some oauth state.

  12. ns-mkusper commented on Mar 29, 2024

    @ns-mkusper
    Author

    Feels strange, unless it is a clientside app that is managing some oauth state.

    It is indeed a client-side app that is managing Oauth state on its own.

  13. Emyrk commented on Mar 29, 2024

    @Emyrk
    Member

    Are you able to share what that app is? @ns-mkusper

  14. ns-mkusper commented on Mar 29, 2024

    @ns-mkusper
    Author
  15. Emyrk commented on Apr 1, 2024

    @Emyrk
    Member

    @ns-mkusper I see. I think this is a general problem we might run into more often. Where a client app wants to manage the token lifecycle.

    I think allowing Coderd & a clientside app to manage a token is not a can of worms I'd like to open.

    A better approach would be to generate a fresh token for each workspace. The external auth token could be used by the startup scripts to create a new one. Cleaning up tokens might not be trivial if they have a long TTL.


    As a summary though, I am going to close this issue. I appreciate the communication of the challenges you are facing. If this arises for other apps and clients, I'll merge things into a larger ticket 👍

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

Metadata

Metadata

Assignees

Labels

apicli

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions