Replies: 2 comments
-
|
That authorize URL isn't valid. You're missing a bunch of parameters. |
Beta Was this translation helpful? Give feedback.
-
|
I finally figured out how to get WinUIEx to work with identity server. This was a long and arduous journey so I'm going to fully explain how I got this working for anyone else that runs into this issue. @dotMorten I would love to buy you a coffee but github no longer accepts paypal and I'm not comfortable giving them my info, so please let me know if there is another way to show my appreciation. First I will be making some assumptions. I will assume that you are trying to get this working for a .net maui project. I will assume that you have already gone through the steps of implementing the "Web Authenticator" into your project. I would follow this guide but what I found to be far more helpful was just making sure that my maui project matched the sample maui project by the duende developers that you can find here. I will also assume that you have your identity server configured properly or you can also just hit the duende demo site instead. Now if your maui project has been setup correctly, you should be able to get authentication working for the iOS and android version of the app. However if you try the windows version, you will encounter an error saying that the web authenticator is not compatible with windows. This has been a long standing bug/issue and sadly it does not appear that Microsoft will be fixing this anytime soon as they closed the ticket without any indication if or when they plan to fix this. This is where WinUIEx comes in. To get started with WinUiEx I recommend following the instructions on their site for maui specifically here. Now a word of caution! At the time of this writing, the latest version of WinUiEx is 2.9.0. I couldn't get this version to work, it complained about not being able to load some dependencies. The version I'm running on is 2.4.1. Also I'm running on .net 9.0.120 and I didn't have to modify my "Microsoft.WindowsAppSdk" version. Now onto the code! I'm assuming that you have a button that you are going to click to initiate the login. I'm also going to use Duende's identity server demo for this. Below is the code that resides inside of my "LoginClicked" method: Below is the two private methods I used above. These methods were not my own and I found them here. A few remarks about the above code. If the client you are attempting to authenticate against requires PKCE then you will need to generate a challenge code and use the code verifier to get the access token. The code verifier code that I used is NOT my own and I have put a link to where I got it to make sure the author gets proper credit. When you run the code and click the login button, a web page will open up allowing you to authenticate. After you do so you will get a dialog asking you to allow the link to open your maui app. When you click on it you will be taken back to your app and if all goes according to plan, you should see your access token, refresh token and claims. Note that the result from calling "AuthenticateAsync" with WinUiEx will have a "Properties" dictionary populated. One of those values will be a code that you can then use to call back into identity server to retrieve your access and refresh token. The code verifier is needed to verify that nothing was tampered with. I hope that this was helpful. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have the below code and when I run it, my identity server complains that the client_id is missing. Is there a place where I can find an example of how to connect to IDS, I have spent a few hours searching but haven't found anything.
Beta Was this translation helpful? Give feedback.
All reactions