Mark
Mark

Reputation: 35

Azure App Services - Google account Id's not matching

I'm testing out Azure App services to create a web / mobile app. I'm using xamarin.forms for mobile, App Services Mobile Services (C# server) for mobile access and 2 App Services Web Apps.

The server app and both web apps have been configured to use Google Auth, using the same Google Credentials as per the instructions here:

https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-how-to-configure-google-authentication/

I'm trying to get the user ID for a logged in Google User, and on the web apps I get an ID in the format 112567911111837839502 (matches for both web app 1 and web app 2), but when I login with the same Google account via mobile I get an ID in the format sid:dc7a23bc80cb2752822351cf5a111111 (both on the mobile client and the mobile server project)

The code I'm using in the web apps and the mobile server project to get the ID's is the same:

var claimsPrincipal = this.User as ClaimsPrincipal;
        string sid = claimsPrincipal.FindFirst(ClaimTypes.NameIdentifier).Value;

Can anyone suggest a way to get matching IDs from Mobile and Web Apps? I had thought this would be one of the main ideas of Azure App Services

Thanks

Mark

Upvotes: 1

Views: 48

Answers (2)

Mark
Mark

Reputation: 35

Found the answer at this link, section "How to: Retrieve authenticated user information"

https://azure.microsoft.com/en-us/documentation/articles/app-service-mobile-dotnet-backend-how-to-use-server-sdk/#how-to-work-with-authentication

The following code works from the Controller

GoogleCredentials cred = await this.User
            .GetAppServiceIdentityAsync<GoogleCredentials>(this.Request);
        var googleId = cred.UserClaims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;

Hope this helps anyone else looking for this

Upvotes: 0

Adrian Hall
Adrian Hall

Reputation: 8035

You can get the /.auth/me endpoint (https://yoursite.azurewebsites.net/.auth/me) - this will give you a JSON object that you can parse for the claims that google is returning. Your UserId will be in there.

Upvotes: 1

Related Questions