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

<token-identified principal>'. Token is expired. #1273

Closed
richard457 opened this issue Jul 14, 2021 · 3 comments
Closed

<token-identified principal>'. Token is expired. #1273

richard457 opened this issue Jul 14, 2021 · 3 comments

Comments

@richard457
Copy link

richard457 commented Jul 14, 2021

Expected behavior:

Every time I connect to SQL with a new token it should work.
I connect on SQL using the azure active directory where I use idToken to get an access token on user behalf to access the DB

var data = qs.stringify({
        'grant_type': 'urn:ietf:params:oauth:grant-type:jwt-bearer',
        'client_id': '2cc13032-21b-XXX',
        'client_secret': 'XXAhCu~XX',
        'assertion': idToken,
        'scope': 'https://database.windows.net//.default',
        'requested_token_use': 'on_behalf_of'
    });
    var configs = {
        method: 'post',
        url: 'https://login.microsoftonline.com/a5eda077-a7ca-4345-9a0b-b2/oauth2/v2.0/token',
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        },
        data: data
    };
    // https://github.com/tediousjs/tedious/blob/master/examples/transaction.js
    return axios(configs);

after getting the the access token from the above code then I pass it to the SQL to connect

    return {
        server: 'gb-sqlsrv.database.windows.net',
        database: 'bd',
        encrypt: true,
        port: 1433,
        type: 'azure-active-directory-access-token',
        authentication: {
            type: 'azure-active-directory-access-token',
            options: {
                token: token
            },
        },
        options: {
            database: 'db',
            encrypt: true,
            port: 1433
        }
    }
}
let dbConfig = config(token)
await sql.connect(dbConfig)

The first time when server start it works which means on Azure active directory side permission are propper set

Actual behaviour:

After some time it shows Login failed for user ''. Token is expired even when I know I am passing a
new token. unless I kill the server and restart it the error keeps showing, my question why this error when on mssql side I am passing a token that I know it has not expired?

Configuration:

"mssql": "^7.1.3",
"next js":latest

// paste relevant config here

Software versions

  • NodeJS:
  • node-mssql:
  • SQL Server:
    @dhensby please help me.
@dhensby
Copy link
Collaborator

dhensby commented Jul 14, 2021

Sounds like a duplicate of #1122 - related: tediousjs/tedious#1144

@richard457
Copy link
Author

As far I can see there is no solution for now? then is there a workaround @dhensby

@dhensby
Copy link
Collaborator

dhensby commented Jul 14, 2021

You will have to destroy and recreate the pool everytime the token expires.

@dhensby dhensby closed this as completed Jul 14, 2021
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