使用Gmail APIs遇redirect_uri_mismatch错误,求Asp.Net+Angular2解决方案
redirect_uri_mismatch Error for Gmail API in ASP.NET API + Angular 2 This error is super common when the redirect URI your app sends in the OAuth authorization request doesn’t exactly match what’s configured in your Google Cloud Console OAuth credentials. Let’s walk through the fix step by step:
Navigate to your Google Cloud Console OAuth credentials
Open your project in Google Cloud Console, then go to APIs & Services > Credentials. Locate the OAuth 2.0 Client ID you created for your app (it should be marked as a "Web application" type).Add the mismatched URI to authorized redirect URIs
Click the edit icon on your client ID, scroll down to the Authorized redirect URIs section, and add the exact URI from your error:http://127.0.0.1:50528/authorize/. Pay attention to every detail—port numbers, trailing slashes, even127.0.0.1vslocalhostare treated as different URIs, so don’t swap them out.Double-check your app’s internal configuration
Make sure your ASP.NET API uses this exact redirect URI in its OAuth setup code. For your Angular 2 frontend, if it’s initiating the auth flow, confirm it’s passing the correct redirect URI to either your backend or directly to the Gmail API endpoint.Wait for configuration changes to propagate
Google’s credential settings can take a couple of minutes to update. After saving your changes, give it 2-3 minutes before testing again to avoid hitting false errors.Prep for production (later on)
When you deploy your app to a live environment, don’t forget to add your production domain’s redirect URI (likehttps://yourappdomain.com/authorize/) to the authorized list—don’t leave only the local development URI in place.
A quick pro tip: If you test locally with both localhost and 127.0.0.1, add both URIs to the authorized list upfront to avoid similar mismatch headaches down the line.
内容的提问来源于stack exchange,提问作者Husam

