Getting started: LCS Authorization? #740
Replies: 8 comments 8 replies
-
Because the error is: I can see that you are working with If you can obtain the token and pass it into jwt.ms / jwt.io - then we can learn more about the token and see if that leads us some places. I have a gut feeling: We are hitting the NON-GOV Azure AD endpoint - but MSAL.PS redirects you correctly. The token analysis will show more. |
Beta Was this translation helpful? Give feedback.
-
Thanks for reporting. As @Splaxi mentioned, the As a potential workaround, have you tried using the token obtained with MSAL.PS with the other d365fo.tools LCS cmdlets? Apart from the token analysis, you can also try tools like Fiddler to analyze and compare the LCS requests sent out by MSAL.PS and On a more general note, you are right, the authorization with LCS is something many are struggling with. We try our best to provide help, but more often than not, the issue is not with d365fo.tools, but the setup of user/app registration/LCS/AD. Suffice to say, it is a complex topic, especially if you wander off the most commonly used path. I will try to get myself acquainted with MSAL.PS and see if that uncovers anything useful. |
Beta Was this translation helpful? Give feedback.
-
Oh wow, thanks for both replies, (I'm rather new to dealing w/most of this). I should have specified: Azure AD tenant where the user and app reg are in is commercial Azure, only the final LCS project/endpoint is gov, however we can test using our/the commercial one as well. (We have some projects in commercial, are in process of migrating to gov) Decoding the JWT I see that the "aud"(ience) field has the gov LCS URL, which makes sense as when calling MSAL module we specify I see both Invoke-PasswordGrant and Invoke-Authorization handle |
Beta Was this translation helpful? Give feedback.
-
I would like you to compare 2 tokens, one from each. My gut feeling is saying that iss(uer) would be totally different... |
Beta Was this translation helpful? Give feedback.
-
No luck with MSAL.PS so far on my end. I am also hampered by not having access to an Azure AD I can play around with. @OranguTech If you can, please provide the script you use to obtain the token with MSAL.PS. The documentation for @Splaxi Regarding your comments on AZ endpoint and issuer, do you mean the authorization provider URI? If so, then yes, this could be a/the issue. |
Beta Was this translation helpful? Give feedback.
-
@OranguTech Thanks, that did the trick. Not sure what I did wrong yesterday. So as far as I can tell, the tokens returned by @Splaxi For me, both tokens have |
Beta Was this translation helpful? Give feedback.
-
@OranguTech I used the following script: $token = Get-MsalToken -ClientId $LCS_ClientId -TenantId $TennantCom -Scope "https://lcsapi.lcs.dynamics.com/.default" -UserCredential $cred -Verbose
Get-D365LcsDatabaseBackups -Latest -ProjectId $LCS_ProjectId -BearerToken $token.AccessToken -LcsApiUri $LCS_ApiUri -Verbose So you don't have to use the configuration returned by Could you also try https://gist.github.com/FH-Inway/cbd0e0fea95a50311bb92540ef94b6e8 ?
You can use the |
Beta Was this translation helpful? Give feedback.
-
Dang you guys have been busy. Could someone conclude where we are, what we (d365fo.tools) is missing and what @OranguTech needs in terms of getting truly unblocked? |
Beta Was this translation helpful? Give feedback.
-
Hello, this module looks great, however getting started has been a bit tricky.
From what I've gathered (from blog posts), Get-D365LcsApiToken is the first step.
Fortunately we've already been able to make use of the LCS "DB Movement" API, using the MSAL.PS module to get an auth token.
(We have a working App Registration w/ delegated permissions granted, and a user account that doesn't have MFA enabled.)
Get-D365LcsApiToken -ClientId $AppReg -Username $Service_userName -Password ($notSecret) -LcsApiUri 'https://lcsapi.gov.lcs.microsoftdynamics.us' -EnableException -Verbose -ErrorVariable APITokenError
Gives only
[Invoke-Authorization] Something went wrong while working against Azure Active Directory (AAD) | Response status code does not indicate success: 400 (Bad Request)
Grabbing the error yields
Invoke-RestMethod: {"error":"invalid_grant","error_description":"AADSTS50126: Error validating credentials due to invalid username or password.
However, I've triple checked the username/password as being correct. I tried the default LCS url ('https://lcsapi.lcs.dynamics.com') since our User/Reg is a different, commercial Azure AD, but It's failing on the auth part, I don't think it's even attempting to talk to LCS yet.
Checking the (machine-generated) password, I see it has a backslash
\
in it. I've tried going throughget-d365lcsapitoken.ps1 -> invoke-passwordgrant.ps1 -> invoke-authorization.ps1
(andconvert-hashtoargstringswitch
) to troubleshoot but so far everything looks like it's okay. (Running our password string through [System.Uri]::EscapeDataString and back through UnescapeDataString shows it seems fine)Any further ideas on troubleshooting this without changing the password?
Again, same user/password and appregistration works using MSAL.PS
Beta Was this translation helpful? Give feedback.
All reactions