Use google token to create youtube service in xamarin android

I’m new to auth0 and i’m probably asking a basic question but how can we create an instance of a google service (youtube, google drive…) in xamarin or android. Should we create a credential from the token or is there an other way ?

This is the code i use to create the youtube service:

GoogleCredential credential = GoogleCredential.FromAccessToken(loginResult.AccessToken);

Console.WriteLine("Credential created");

YoutubeEngine.youtubeService = new YouTubeService(new BaseClientService.Initializer()
{
    HttpClientInitializer = credential,
    ApplicationName = "MusicApp"
});

but the app crash with a “An unhandled exception occured” error when i use the youtube service.

Have in mind that if you performed the end-user authentication through Auth0 even if the end-user ultimately authenticated against Google the tokens provided to your client application were issued by Auth0 and are only applicable to endpoints known to Auth0. That is, if the access token in the snippet was issued by Auth0 then it won’t be applicable for what you intend as it seems you’re initializing a Google SDK that would call Google endpoints.

It’s true that as part of the authentication flow brokered through Auth0 there were access tokens issued by Google which could be applicable for your use case, however, these are issued as part of a server-side flow between Google and the Auth0 service associated with your tenant/domain and are not made available to the client application by default.

If you check the documentation you’ll also notice that there is a way for a client application to obtain those upstream identity provider access tokens, but it implies to go through the Auth0 Management API which requires a confidential client and a native application is considered a public client. Based on the information provided in the question your scenario requires that the client application obtains access tokens suitable for Google and directly with Google.