Bentley Communities
Bentley Communities
  • Site
  • User
  • Site
  • Search
  • User
ProjectWise
  • Product Communities
ProjectWise
ProjectWise PowerShell Extensions Forum What is the correct usage of New-PWLogin with the -Token argument?
    • Sign In

    • State Suggested Answer
    • Replies 11 replies
    • Answers 1 answer
    • Subscribers 66 subscribers
    • Views 616 views
    • Users 0 members are here
    • New-PWLogin
    • ProjectWise
    • pwps_dab
    • Login Error

    What is the correct usage of New-PWLogin with the -Token argument?

    Olivier Doucet
    Offline Olivier Doucet 7 months ago
    with: 
    $loginSplat = @{
      DatasourceName        = 'server:dsn'
      BentleyIMS            = $true
      UserName              = 'first.last@domain.com'
      Token                 = $AccessToken
      NonAdminLogin         = $true
    }
    New-PWLogin @loginSplat

    I am getting error 58064


    The access token was obtained with:

    $res = Get-OIDCToken   // redirects user to login screen

    $AccessToken = $res.access_token

    • Sign in to reply
    • Cancel

    Top Replies

    • MWBSI
      MWBSI Wed, Feb 22 2023 3:38 PM in reply to Kevin van Haaren +1
      Ok, here's the deal. For New-PWLogin, the Token parameter value will only be used if the -BentleyIMS parameter is specified. The -Token can be used to log in with IMS identities other than the one used…
    • MWBSI
      MWBSI Wed, Feb 22 2023 6:31 PM in reply to Olivier Doucet +1 suggested
      Once you get the token via the method above, you can re-use it. However, you cannot bypass the Connection Client, at least initially. This is by design. Presently you cannot use an OIDC token to log…
    • Kevin van Haaren
      0 Offline Kevin van Haaren Tue, Feb 21 2023 12:25 PM

      If you've got Connection Client open and logged in then don't use either UserName or Token in the login.

      $loginSplat = @{
        DatasourceName        = 'server:dsn'
        BentleyIMS            = $true
        NonAdminLogin         = $true
      }
      New-PWLogin @loginSplat

      that should work

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Olivier Doucet
      0 Offline Olivier Doucet Tue, Feb 21 2023 12:52 PM in reply to Kevin van Haaren

      Thank you for your answer Kevin van Haaren I can 'make it work'
      But my question is how to correctly login with New-PWLogin using the -Token argument.

      For instance, should one specify the user name or not.
      What constitutes a valid token in this case?
      Are there other arguments of New-PWLogin (besides -Password and -UseGui) that are not compatible with -Token?
      Etc.

      Maybe you can also speculate on why it fails in my case.

      And also why the -Token argument exists in the first place.

      Thank you for your help.

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Kevin van Haaren
      0 Offline Kevin van Haaren Wed, Feb 22 2023 2:19 PM in reply to Olivier Doucet

      Not completely sure on any of those questions. I'm also not sure if the token it expects is the Get-OIDCToken token or one of the others. When I initially got IMS logins working I figured I needed the Token and tried to get it to work a bunch of different ways. None of them worked. When I figured out I didn't need it I gave up on it.

      I'm not sure why it exists since I've never gotten it to work. Ideally I'd like to use it in a scheduled task on a machine where Connection Client isn't running but it's possible to generate a token that lets the process login with a logical account. Not sure if that is the intent though.

      After your question i played with a bunch more options and still couldn't get it to work, except in one case. The one scenario where I got it to work was occasionally it worked if I did:

      $token = Get-OIDCToken

      New-PWLogin -DatasourceName 'server:dsn' -BentleyIMS -Token $token.id_token

      But it turns out that sometimes the id_token property is null so the case above worked because I was doing -BentleyIMS without actually specifying a token.

      if you do: get-command -Module pwps_dab -Name '*token*'

      you'll see quite a few commands that get various token types. I tried man of them and couldn't get them to work.

      ConvertFrom-EncodedToken
      ConvertTo-EncodedToken
      Get-ADFSToken
      Get-AzureIOTToken
      Get-EncodedLogicalToken
      Get-OIDCToken
      Get-PWConnectionClientToken
      Get-PWConnectorToken
      Get-PWDMServiceAccountToken
      Get-PWNonFederatedLoginToken
      Get-PWUserPasswordToken
      Show-PWTokenFormatted
      Update-OIDCToken

       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • MWBSI
      0 MWBSI Wed, Feb 22 2023 3:38 PM in reply to Kevin van Haaren

      Ok, here's the deal.  For New-PWLogin, the Token parameter value will only be used if the -BentleyIMS parameter is specified.  The -Token can be  used to log in with IMS identities other than the one used to log in to the Connection Client.  These can be federated or non-federated but you have to supply a correctly token.  For instance, it cannot be encoded.   This is rather esoteric functionality.   

      If you specifiy the -BenteyIMS parameter but not the -Token parameter New-PWLogin will, internally get a token from the Connection Client to log in with.  This is probably what you are looking for.

      Hope this helps,

      Mark Weisman | Bentley Systems

      • Cancel
      • Vote Up +1 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    • Olivier Doucet
      0 Offline Olivier Doucet Wed, Feb 22 2023 5:43 PM in reply to MWBSI

      Thanks for your answer MWBSI 

      My goal here is to login without the connection client.
      Good to know that the connection client will interfere with the process. So I disconnected from it and tried again. But still no success :/

      1) Although it was not answered explicitly, I assume that when using -BenteyIMS and -Token, the arg -UserName should *not* be provided. Great if you could confirm that.

      2) When obtaining the token with:
      $token = Get-OIDCToken
      I assume that the value the -Token arg expects is $token.access_token and not $token.id_token as suggested by  Kevin van Haaren Great if that could be confirmed as well.

      3) What do you mean by "it cannot be encoded." about the token? Can I pass $token.access_token to -Token? Else could you illustrate how to decode it?

      You have no idea how time-consuming this detective work takes. Hopefully you can shed more light on this mystery.
      Thanks again!

       
       

      • Cancel
      • Vote Up 0 Vote Down
      • Sign in to reply
      • Verify Answer
      • Cancel
    >

    Communities
    • Home
    • Getting Started
    • Community Central
    • Products
    • Support
    • Secure File Upload
    • Feedback
    Support and Services
    • Home
    • Product Support
    • Downloads
    • Subscription Services Portal
    Training and Learning
    • Home
    • About Bentley Institute
    • My Learning History
    • Reference Books
    Social Media
    •    LinkedIn
    •    Facebook
    •    Twitter
    •    YouTube
    •    RSS Feed
    •    Email

    © 2023 Bentley Systems, Incorporated  |  Contact Us  |  Privacy |  Terms of Use  |  Cookies