Getting Connection Reset Issue while Fetching Azure Access Token - azure

hope everyone is well.
I am using azure library to fetch access token using the below code snippet, but getting an error
Execution of class com.microsoft.aad.msal4j.AcquireTokenByAuthorizationGrantSupplier failed.
com.microsoft.aad.msal4j.MsalClientException: java.net.SocketException: Connection reset
When I enclose the code in try catch, it gets catched as an ExecutionException.
Below is the code snippet.
ConfidentialClientApplication app = ConfidentialClientApplication.builder("XXX", ClientCredentialFactory.createFromCertificate(XXX, "")).authority("https://login.microsoftonline.com/XXX").build();
ClientCredentialParameters clientCredentialParam = ClientCredentialParameters.builder(Collections.singleton(String.format(https://graph.microsoft.com/.default))).build();
CompletableFuture future = app.acquireToken(clientCredentialParam);
//call to future.get() function
I appreciate if anyone could help me in this issue as I am unable to find any solution for this for the past 2 weeks, tried so many ways but no success.
Thanks

Related

Azure Table Storage query failed with authentication error (Received:Forbidden) from time to time

Environment: Azure app service.
Azure storage SDK: WindowsAzure.Storage (9.3.3)
Invocation (pseudo code):
void QueryAzureTable(){
while(true){
var tableClient = new AzureTable();
var resp = tableClient.Query('table','pk','rk');
// ...
}
}
var tasks = new List<Task>();
for (var i = 0; i < 5; i++)
{
tasks.Add(QueryAzureTable());
}
await Task.WhenAll(tasks).ConfigureAwait(false);
Authorization method for QueryAzureTable: tried with both clientId/secret and managed identity/MSI, same result for both.
Observation:
Around half of the requests failed due to anth issue in QueryAzureTable() (see detailed error msg below).
If I restart the azure app service instance, the auth error will be gone for ~12 hours.
Error Message:
Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature.
Unexpected response code, Expected:OK or NotFound, Received:Forbidden
I have checked and tried with almost every solutions mentioned in this stackoverflow thread, but no luck.
Guess this specific auth issue might be related with multi-tasks.
Kind of figured out the solution on my own: adding a retry logic to renew the token.
void query(...){
int cnt=0;
while(true){
try{
_client.queryTable(...);
}
catch(AuthException ex){
log.error(ex...);
var token=new Token(...);
_client = new AzureTableClient(token);
cnt++;
if(cnt==3) throw;
}
}
}
The first clue to this solution was whenever there was a app service release, deployment or restart of the app service, the query table function worked well for a while, and then after around 12 hours, errors started showing up. But not 100% failure rate.
If there is any explanation or conclusion that helps to root cause this, please share your opinions. Thanks in advance!
My blind guess is that it has something to do with muti-tasks: WindowsAzure.Storage (9.3.3) does not do a good job of renewing token for muti-tasks.
Hope this could help you.

Exception: 401 Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential

I've seen a few people over the years facing similar issue but I haven't found much regarding my case.
I have a backend built with python3.
I am using firebase_admin as a library to connect to Firebase Cloud Firestore.
I then commit my code to Github and using Github Actions
I am deploying the docker container to Google Cloud Run.
This all works fine for some time
Some time later throws the following exception: Exception: 401 Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.
What am I doing wrong?
Should I connect every time I call the function? (move the db initialization in each function call)
Feels like the token expired. Can I refresh it somehow?
Python code:
from firebase_admin import firestore, initialize_app
initialize_app()
db = firestore.client()
def get_info_from_firestore(name: str:
try:
data = db.collection(u'data').where(u'title', u'==', name).stream()
for rating in ratings:
return rating.to_dict()
return None
except Exception as e:
logging.warning(Exception: {e}')
return None
And this file is imported from my root python file that's using Flask.
Edit: One final thing that might help, if I redeploy my container without any changes it all works again.
Likely this is happening due to time drift: time in docker significatly differs realtime. After restart time is in sync but after a while it drifts. Google does not like it. See more info about this WSL/container issue here https://github.com/microsoft/WSL/issues/4245 and here https://github.com/docker/for-win/issues/4526

Generating token for connecting to azure sql takes too long

I am trying to fetch token using GetAccessTokenAsync in C#, the code works fine and I am able to connect but the issue is it's taking too long to generate token(around 30 sec). Does anyone else facing similar issue?
var conn = (SqlConnection)this.Database.GetDbConnection();
conn.AccessToken = new AzureServiceTokenProvider()
.GetAccessTokenAsync("https://database.windows.net/")
.Result;
Can you please disable telemetry and try? Details are here. I believe it is the collect_telemetry option.

Jira authentication struggle

I'm using jira-python library to gain API access to our company account on Jira.
This is the block of code that should work according to the docs:
from jira.client import JIRA
jira = JIRA(options={'server': 'https://jira.xyz.co.uk'},
basic_auth=('marek#xyz.co.uk', 'my_token'))
Taking into account the fact that cookie-based authentication no longer works I generated API tokens and parsed them into code, yet I'm getting error:
WARNING:root:Got recoverable error from GET https://jira.xyz.co.uk/rest/api/2/serverInfo, will retry [2/3] in 5.527397890949137s. Err: 401
And this just loops and loops until I hit Ctrl+c.
I found this topic here Issue in connecting with JIRA python where somebody asked the very same question but the solution didn't work for me as the missing libraries aren't missing on my system.
What else I could try ?

ASANA Create Task API call stopped working

In the last couple of weeks, Create Task API Call for ASANA stopped working.
This code has been working for last 6 months but now it fails.
The error I get is
The remote server returned an error: (434) Client Error (434).
According to the ASANA website
https://asana.com/developers/documentation/getting-started/errors
434 means Deprecated
but I am not sure what is Deprecated.
Does anybody have any suggestions I can try to get to the bottom of this?
API Key is deprecated.
Use this page to change it: https://asana.com/developers/feed/api-key-deprecation

Resources