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

Redirect URI #3

Open
SUD-D365 opened this issue Aug 8, 2019 · 8 comments
Open

Redirect URI #3

SUD-D365 opened this issue Aug 8, 2019 · 8 comments

Comments

@SUD-D365
Copy link

SUD-D365 commented Aug 8, 2019

Hi @dkatson

I am little bit confused here with your passed parameter $clientRedirectUri in powershell script.
Since, Azure not allowing to write a redirect URI in this format. BusinessCentralWebServiceClient://auth
image

Can you give me some insights?
Thanks

@SUD-D365
Copy link
Author

SUD-D365 commented Aug 9, 2019

Hi @dkatson

Did you faced below error while your development?

Cannot find an overload for "AcquireTokenAsync" and the argument count: "6".
image

Thanks

@DmitryKatson
Copy link
Owner

Hi @SUD-D365

Try this
image

@DmitryKatson
Copy link
Owner

@SUD-D365 Did you run this?
image

@SUD-D365
Copy link
Author

Hi @dkatson ,

Below is what i am trying to run.
image

Function definition for New-PremiumBCCloudSandBoxWithCustomData

function New-PremiumBCCloudSandBoxWithCustomData {
param
(
[Parameter(Mandatory=$true)]
[string] $url,
[Parameter(Mandatory=$true)]
[string] $appId,
[Parameter(Mandatory=$true)]
[string] $DAemail,
[string] $DApassword,
[Parameter(Mandatory=$true)]
[string] $tenantdomain,
[Parameter(Mandatory=$true)]
[string] $sandboxName,
[Parameter(Mandatory=$true)]
[string] $companyName

)

$startTime=(Get-Date);
Clear-Host

# Connect to admin Center
$authHeaderDA = GetAuthHeader -DAemail $DAemail -DApassword $DApassword -tenantdomain $tenantdomain -appId $appId

Write-Host $authHeaderDA

$Elapsed = (Get-Date)-$startTime;

}

Function definition for GetAuthHeader
function GetAuthHeader
{
[CmdletBinding()]
param
(
[Parameter(Mandatory=$true)]
[string] $DAemail,
[string] $DApassword,
[Parameter(Mandatory=$true)]
[string] $tenantdomain,
[Parameter(Mandatory=$true)]
[string] $appId
)

Write-Host "Checking for AzureAD module..."
if (!$CredPrompt){$CredPrompt = 'Auto'}
$AadModule = Get-Module -Name "AzureAD" -ListAvailable
if ($AadModule -eq $null) {$AadModule = Get-Module -Name "AzureADPreview" -ListAvailable}
if ($AadModule -eq $null) {write-host "AzureAD Powershell module is not installed. The module can be installed by running 'Install-Module AzureAD' or 'Install-Module AzureADPreview' from an elevated PowerShell prompt. Stopping." -f Yellow;exit}
if ($AadModule.count -gt 1) {
    $Latest_Version = ($AadModule | select version | Sort-Object)[-1]
    $aadModule      = $AadModule | ? { $_.version -eq $Latest_Version.version }
    $adal           = Join-Path $AadModule.ModuleBase "Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
    $adalforms      = Join-Path $AadModule.ModuleBase "Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll"
    }
else {
    $adal           = Join-Path $AadModule.ModuleBase "Microsoft.IdentityModel.Clients.ActiveDirectory.dll"
    $adalforms      = Join-Path $AadModule.ModuleBase "Microsoft.IdentityModel.Clients.ActiveDirectory.Platform.dll"
    }
[System.Reflection.Assembly]::LoadFrom($adal) | Out-Null
[System.Reflection.Assembly]::LoadFrom($adalforms) | Out-Null

if ($DApassword) {

    $cred = [Microsoft.IdentityModel.Clients.ActiveDirectory.UserPasswordCredential]::new($DAemail, $DApassword)
    $ctx  = [Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext]::new("https://login.windows.net/$tenantdomain")
    $client_secret = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
    $token = [Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContextIntegratedAuthExtensions]::AcquireTokenAsync($ctx, "https://api.businesscentral.dynamics.com", $appId, $client_secret, $cred).GetAwaiter().GetResult().AccessToken

    if ($token) { Write-Host -ForegroundColor Green "Successfully connected to Cloud Business Central"}
    if (!$token) { Write-Host -ForegroundColor Red "Connection to Cloud Business Central failed"}

    return "Bearer $($token)"

} 
else {

    $authority = "https://login.windows.net"
    $resource    = "https://projectmadeira.com"    
    $clientRedirectUri = [uri]"BusinessCentralWebServiceClient//auth"     
    

    $authenticationContext = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext -ArgumentList "$authority/$tenantdomain"
    $platformParameters = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.PlatformParameters -ArgumentList ([Microsoft.IdentityModel.Clients.ActiveDirectory.PromptBehavior]::Always)
    $userIdentifier = New-Object Microsoft.IdentityModel.Clients.ActiveDirectory.UserIdentifier -ArgumentList ($DAemail, [Microsoft.IdentityModel.Clients.ActiveDirectory.UserIdentifierType]::RequiredDisplayableId)
    $authenticationResult = $authenticationContext.AcquireTokenAsync($resource, $appId, $clientRedirectUri, $client_secret, $platformParameters, $userIdentifier).GetAwaiter().GetResult()

    if ($authenticationResult.AccessToken) { Write-Host -ForegroundColor Green "Successfully connected to Cloud Business Central"}
    if (!$authenticationResult.AccessToken) { Write-Host -ForegroundColor Red "Connection to Cloud Business Central failed"}

    return "$($authenticationResult.AccessTokenType) $($authenticationResult.AccessToken)" 
}    

}

Thanks

@SUD-D365
Copy link
Author

@SUD-D365 Did you run this?
image

Yes i ran this.

@SUD-D365
Copy link
Author

Hi @SUD-D365

Try this
image

It worked for me. Thanks

@DmitryKatson
Copy link
Owner

Hi @dkatson

Did you faced below error while your development?

Cannot find an overload for "AcquireTokenAsync" and the argument count: "6".
image

Thanks

Check here please microsoftgraph/powershell-intune-samples#3

@SUD-D365
Copy link
Author

SUD-D365 commented Aug 27, 2019

Seems like i have resolved this issue.
Also i got a bearer key like you mentioned in blog.
How do i know that sandbox is created?
Or this was only about to linking with cloud business central services.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants