Is there a way to set a custom Bearer Access Token within the "angular-oauth2-oidc" package?

Issue

I have created a custom endpoint for my Facebook login. This endpoint receives the Facebook access token from the client. I get this token inside my client (Ionic App) with the ‘@ionic-native/facebook/ngx’ package.

Inside a controller in the Laravel Json API I search for the user with Socialite, with the Facebook access token inserted. After getting the user, I generate a Bearer access token out of it. The response is this Bearer access token.

After fetching this Bearer access token inside my client, I need to add it somehow to the “angular-oauth2-oidc” service. I already have a normal password flow, but how do I implement a custom implicit flow, so that I can set this given Bearer Access Token to my service?

I have tried the tryLogin() but this method only works for my normal login endpoint. I do have two endpoints now: ‘…/oauth/token’ (normal) ,and ‘…/oauth/facebook/token’ (facebook).

public setAccessToken(bearerAccessToken){
//Code to set the given access token in my oAuthService
}

I want this to work somehow.

canActivate() {
  return this.oAuthService.hasValidAccessToken() ||
      this.router.parseUrl('/landing-page');
  }

This is my guard. If my Bearer access token is set, hasValidAccessToken() has to return true.

I expect that there is a setAccessToken function somewhere in “angular-oauth2-oidc” that I can use.

Solution

Found the solution myself, the following solved the issue:
this.oAuthStorage.setItem('access_token', bearerAccessToken);

Answered By – Stefan

Answer Checked By – David Marino (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.