Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IPlatformParameters in ADAL

Tags:

vb.net

adal

I am by all means a newbie to VB.net. I am seeking your help here.

I am writing a code to connect to REST API. I am having difficulties with passing one parameter to a function. Here is my code:

Dim AuthContext As New AuthenticationContext("https://login.microsoftonline.com/")
        Dim ClientId As String = "f8f710b23-d3ea-4dd3-8a0e-c5958a6bc16d"
        Dim RedirectUri As New Uri("ms-app://redirect/")
        Dim ResourceIDUri As String = "https://analysis.windows.net/powerbi/api"
        Dim AccessToken As String
        Dim AuthHeader As String
        Dim task1 As Task(Of AuthenticationResult) = AuthContext.AcquireTokenAsync(ResourceIDUri, ClientId, RedirectUri, New IPlatformParameters(PromptBehavior.Auto), New UserIdentifier("user1", 2))

and my issue is with the parameter (New IPlatformParameters(PromptBehavior.Auto)) as I get the following error:

'New' cannot be used on an interface

Here is the documentation for AccuireTokenSync

Can someone guide me to correct syntax of passing the parameter IPlatformParameters(PromptBehavior.Auto)

like image 879
Waddah Shamroukh Avatar asked Feb 18 '26 16:02

Waddah Shamroukh


1 Answers

Do this:

result = await ac.AcquireTokenAsync("<clientId>", "https://resourceUrl", new Uri("https://ClientReplyUrl"), new PlatformParameters(PromptBehavior.Auto));

Here's a link to the ADAL .NET wiki which details how to use the PlatformParameters. 'parameters' of type 'PlatformParameters' is the ADAL.NET way of expressing what kind of interaction needs to happen with the user.

Auto the user is prompted for credentials only when needed.

  • If a token already exists in the cache, no dialog is presented at all.
  • If no token exists in the cache, but the user is known, or a session cookie is available in the web browser control used for the interaction, the dialog flashes but disappears immediately.
  • If no token exists in the cache and the user is not known, the dialog is presented for the user to log-in

Always the user is always prompted for credentials, even if a token exists in the cache, and if a user has a session. This is useful when the application wants to give the user an opportunity to sign-in with a different identity without giving any hint of previous identities.

RefreshSession the web browser is displayed, and the token gets updated claims. If the logon cookies are available (in the embedded web view) the user won't be prompted for credentials, and the dialog will quickly disappear (there will be a flash).

SelectAccount this shows a dialog containing the identities under which the user has currently sessions. The user can add other accounts.

Never [except on Android and iOS]: does not prompt the user for credentials.

CallerActivity [Android] or OwnerWindows [.NET 4.5] enable application developers to control what window/activity will be the parent of the authentication dialog. A developer might want to provide this parent information for UX reasons: to ensure that the dialog to appear centered on the parent window and over it.

like image 73
Jenny Avatar answered Feb 20 '26 17:02

Jenny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!