-
Notifications
You must be signed in to change notification settings - Fork 67
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
Feature/b2c support #48
Conversation
- changed key construction to be generic, instead of depending on x5c field - added an option openid_config parameter
- this doesn't fix all the tests yet
Thank you so much! I’ll look into tests as soon as I can, but it might take a few days. 😊 |
You could look into creating the signing key from jwk instead of manually like I’ve done? Seems like it loads a bit more than just the public key. |
Hi @robteeuwen ! I did some research over lunch and think I figured it out. In short, These matters so much now, because Since Azure keys always consist of both Wrap that in jwk.construct(
signing_key_b.private_bytes(
crypto_serialization.Encoding.PEM,
crypto_serialization.PrivateFormat.PKCS8,
crypto_serialization.NoEncryption(),
),
'RS256',
).to_dict() Let me know if anything is unclear. 😄 |
I wanted to learn how to actually convert base64.b64encode(signing_key_b.public_key().public_numbers().e.to_bytes(((signing_key_b.public_key().public_numbers().e.bit_length() + 7) // 8), 'big'))
base64.b64encode(signing_key_b.public_key().public_numbers().n.to_bytes(((signing_key_b.public_key().public_numbers().n.bit_length() + 7) // 8), 'big')) Where The RFC says
which under Terminology can be read about:
and now my head is boiling. Looking at the python-jose code, I can't find this solution, so I am sure it is a better way. 😄 |
hey Jonas, thanks so much for looking into this. I'm not sure I'm following completely. I tried to make some changes like the ones you suggest, but my tests are still failing. So first things first, do you think I'm generating the cert_obj incorrectly in the application code (here) or do you think they keys are only generated incorrectly in the tests? |
@robteeuwen , I've commited to your branch which should fix it. Let me know if you want me to describe the changes in detail. I also ran linting. Please run EDIT: This was a great article about these concepts. |
Codecov Report
@@ Coverage Diff @@
## main #48 +/- ##
=======================================
Coverage 100.0% 100.0%
=======================================
Files 5 5
Lines 173 174 +1
=======================================
+ Hits 173 174 +1
|
Why is it required to pass in |
That's a good question. In my organization's case the domain is different for B2C (it's a custom domain). This may be non standard, but in general, I think it's nice to have the option to override the config_url, since you can also override the other urls. But I set it to optional, so it's not required to pass it. In case this is non-standard B2C behavior, I guess it doesn't technically belong to the same feature as adding B2C support, so maybe it belongs in a different PR. Another thing that's different is that B2C openid config url includes a policy: https://docs.microsoft.com/en-us/azure/active-directory-b2c/openid-connect |
Aha, so you can customize that URL in B2C, I didn't know. In the normal single- and multi-tenant situations these can be generated by the other settings. As for the policy: anything in particular you think would require code changes to support? Sorry for the wall of text. 😅 EDIT: I see what you mean about policies now. Should be mostly about extending the config_url indeed. Would love to generate that in the |
Hi @robteeuwen, do you have any questions or want me to help out with something? 😊 |
Hi @robteeuwen , I’ll finish up this PR with the current changes this week if I don’t hear back. The specific B2C class and docs can be another PR, this PR is a nice start to all of that. |
Hi Jonas, I'm sorry for bailing on this, I've been traveling and some other things came up that prevented me from finishing this up. It looks like only the code coverage check is failing, so we're missing a test somewhere? Or did you want me to make other changes to the code? If you could help finishing this up that would be great, otherwise I can get back to it myself in the next couple of weeks. |
No worries! I’ll see what I can do 😊 Yeah, a test or two is missing. Would also love to include documentation(like I have for single- and multi-tenant applications) for B2C, but don’t really need that to merge this. |
I've removed the setting from I've added a test and cleaned up a little. Will merge and release ASAP. |
I've merged and creates a release - thank you so much! I would love documentation(like we got for single- and multi-tenant apps) and a specific |
@robteeuwen thank you for this! do you have some documentation or at least some example code/config you can share to get this setup? |
for now I am seeing if using https://github.com/425show/fastapi_microsoft_identity#2-azure-ad-b2c-authentication gets me started in the right direction |
Feature/b2c support
Added support for tokens without
x5c
fields, and added optionalopenid_config_url
override, this would close #46Not all tests are working yet, not sure if that is due to the code itself or due to the test config