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

[BC Idea]: OAuth2 Authorization with Audience Paramater #2966

Open
1 task done
mjmatthiesen opened this issue Feb 14, 2025 · 4 comments · May be fixed by #3199
Open
1 task done

[BC Idea]: OAuth2 Authorization with Audience Paramater #2966

mjmatthiesen opened this issue Feb 14, 2025 · 4 comments · May be fixed by #3199
Labels
Approved The issue is approved BCIdea Issue related to a BCIdea Integration GitHub request for Integration area Linked Issue is linked to a Azure Boards work item

Comments

@mjmatthiesen
Copy link
Contributor

mjmatthiesen commented Feb 14, 2025

BC Idea Link

https://experience.dynamics.com/ideas/idea/?ideaid=4f0a39a0-eeea-ef11-a4de-7c1e52b9f07c

Description

The idea is simple, add an overload to the current OAuth2 codeunit (and the implementation) that allows adding the audience param to the url. Functionally this is similar but not the same as resource url or a scope.

I could implement OAuth2 myself, but the issue I run into is that I need different callback urls for each environment and I would love to avoid that headache.

If I am good to proceed on this, I can create a PR and implement a method similar to AppendPromptParameter as I am not able to change OAuthAuthorization.CalculateAuthRequestUrl. The latter may have an overload available, but I was not able to inspect it.

I will provide the implementation for this BC Idea

  • I will provide the implementation for this BC Idea
    Internal work item: AB#565907
@mjmatthiesen mjmatthiesen added the BCIdea Issue related to a BCIdea label Feb 14, 2025
@bcbuild-github-agent bcbuild-github-agent added the Linked Issue is linked to a Azure Boards work item label Feb 17, 2025
@mjmatthiesen
Copy link
Contributor Author

@JesperSchulz I see an internal work item was added. Am I good to proceed on this then?

@JesperSchulz
Copy link
Contributor

@mjmatthiesen, sorry, I was out for a while and am trying to catch up on everything here on GitHub 😊
I will approve this one. Sounds fair to me!

@JesperSchulz JesperSchulz added Approved The issue is approved Integration GitHub request for Integration area labels Feb 28, 2025
@mjmatthiesen
Copy link
Contributor Author

@JesperSchulz Not to worry. I just didn't want to spend time on it if it didn't have a chance of merging, because my solution was only theoretical.

Turns out the theory was not entirely sound. After doing some initial work, I realize that I misunderstood what the OAuth2 module is actually capable of. I had made the assumption that it is able to handle oauth for any standard compliant interface. As in the user has a login, authorizes our app on that service, and then gets a refresh and access token that BC stores and we can request for an API call. Adding the audience I can do the login process, but I cannot get the tokens. I understand now that it's out of scope of this codeunit.

I do believe I can leverage the login and callback process to get my auth code and then handle retrieval of tokens myself, but that will require some additional testing from me. Even just that part would greatly simplify it for us.

I did some research and see now that it is structured to always go to login.microsoftonline.com/common/discovery/instance?api-version=1.1&authorization_endpoint=$ where the auth endpoint is an edited version of my original auth endpoint. In my case specifically it goes from

https://BASEURL/authorize/
https://BASEURL/authorize/oauth2/v2.0/authorize

or without the trailing slash it becomes

https://BASEURL/authorize
https://BASEURL/common/oauth2/v2.0/authorize

I guess really the question is if it is out of scope to do something more generic, i.e. use the returned auth code to get the access and refresh token, but maybe that is something MS is already planning for.

mjmatthiesen pushed a commit to mjmatthiesen/BCApps that referenced this issue Mar 7, 2025
mjmatthiesen pushed a commit to mjmatthiesen/BCApps that referenced this issue Mar 7, 2025
@mjmatthiesen mjmatthiesen linked a pull request Mar 7, 2025 that will close this issue
@JesperSchulz
Copy link
Contributor

Let's get some of our security experts on this case. I've pinged them in the linked PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Approved The issue is approved BCIdea Issue related to a BCIdea Integration GitHub request for Integration area Linked Issue is linked to a Azure Boards work item
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants