Failed Silent Auth - Login required : failing when trying get token and authenticate from angular app

Hi Team,

I am totally new to auth0.

I am trying to use it for authenticate my own API using token received from auth0.
I have done following things so far

  1. created API
  2. created demon application (and test also)
  3. using same application’s client ID and secrete key called methods like below( have added node api project for same below)
    var options = { method: ‘POST’,

url: coreConfig.url,
headers: { ‘content-type’: ‘application/json’ },
body: JSON.stringify( {“client_id”: coreConfig.clientId, “client_secret”:coreConfig.client_secret,
“audience”:coreConfig.audience,“grant_type”:coreConfig.grant_type,“prompt”:‘none’ })
};
exports.acquireHeaderInput = function (req, res) {
request(options, function (error, response, body) {
if (error) throw new Error(error);
}).pipe(res)
};

  1. when I call this method from postman I get proper response
  2. then I tried to call api method from my angular app and get response but there its giving error “Failed Silent Auth - Login required”
  3. I have intercepted httpclient call from my angular app to my own api. So as expected its calling auth0 but not responding with token

Please check below code and help to identify where I am making mistake.

export class InterceptorService implements HttpInterceptor {

constructor(private auth: AuthtokenService) { }

intercept(

req: HttpRequest<any>,

next: HttpHandler

): Observable<HttpEvent> {

// console.log(“Core app intercept”);

return this.auth.getTokenSilently$().pipe(

  

  mergeMap(token => {

// console.log(token);

    const tokenReq = req.clone({

      setHeaders: { Authorization: `Bearer ${token}` }

    });

    return next.handle(tokenReq);

  }),

  catchError(err => throwError(err))

);

}

}


auth0Client$ = (from(

createAuth0Client({

  domain: config.domain,

  client_id: config.clientId,

  redirect_uri: `${window.location.origin}`,

  audience: config.audience

})

) as Observable).pipe(

shareReplay(1), // Every subscription receives the same shared value

catchError(err => throwError(err))

);

// When calling, options can be passed if desired

// https://auth0.github.io/auth0-spa-js/classes/auth0client.html#gettokensilently

getTokenSilently$(options?): Observable {

console.log("get token silently");

// console.log(options);

console.log(this.auth0Client$.subscribe(data=>{

  console.log("in");

  console.log(data);

}))

console.log(this.auth0Client$);

return this.auth0Client$.pipe(

  concatMap((client: Auth0Client) => from(client.getTokenSilently(options)))

);

}

in my existing service
ping$(): Observable {

return this.http.get(config.auth0endpoint +'acquireHeaderInput');

}

below is the log for failed case (when I call from APP)
{
“date”: “2020-02-26T12:16:39.167Z”,
“type”: “fsa”,
“description”: “Login required”,
“client_id”: “XXXX”,
“client_name”: “Core API Access APP”,
“ip”: “42.108.243.77”,
“user_agent”: “Chrome 80.0.3987 / Windows 10.0.0”,
“details”: {
“body”: {},
“qs”: {
“client_id”: “XXX”,
“redirect_uri”: “http://localhost:4200”,
“audience”: “https://XXX/api”,
“scope”: “openid profile email”,
“response_type”: “code”,
“response_mode”: “web_message”,
“state”: “amdoeUxvLmJXVFdsaGhQcU9YYU50TWxIOHdqV0F0Lm16MDlMM1pPeWhqUQ==”,
“nonce”: “REtZCTOjBl2HdwuHG~s_0WyI2gTWV1NojAHjGT89RkU”,
“code_challenge”: “HjwoxR5JdFI4MicWvGR6byjSvOWsM_PLIlspuhqSB80”,
“code_challenge_method”: “S256”,
“prompt”: “none”,
“auth0Client”: “eyJuYW1lIjoiYXV0aDAtc3BhLWpzIiwidmVyc2lvbiI6IjEuNi40In0=”
},
“connection”: null,
“error”: {
“message”: “Login required”,
“oauthError”: “login_required”,
“type”: “oauth-authorization”
}
},
“hostname”: “atos-syntel.auth0.com”,
“audience”: “https://sfca.studios.atos-syntel.net/api”,
“scope”: [
“openid”,
“profile”,
“email”
],
“auth0_client”: {
“name”: “auth0-spa-js”,
“version”: “1.6.4”
},
“log_id”: “90020200226121642273000576013840683799581211422240014418”,
“_id”: “90020200226121642273000576013840683799581211422240014418”,
“isMobile”: false
}

when calling from postman (api which I have created to get token ) get below success message

{
“date”: “2020-02-26T11:52:57.805Z”,
“type”: “seccft”,
“description”: “Client Credentials for Access Token”,
“connection_id”: “”,
“client_id”: “XXXX”,
“client_name”: “Core API Access APP”,
“ip”: “42.106.211.5”,
“details”: {
“device_id”: “v0:87f54560-588e-11ea-aa7f-a9b1717ea131”
},
“hostname”: “atos-syntel.auth0.com”,
“user_id”: “”,
“user_name”: “”,
“audience”: “https://sfca.studios.atos-syntel.net/api”,
“scope”: null,
“log_id”: “90020200226115301472000430354383217266786127742058365042”,
“_id”: “90020200226115301472000430354383217266786127742058365042”,
“isMobile”: false,
“user_agent”: “Other 0.0.0 / Other 0.0.0”
}

have you found the solution as I’m facing the same issue.