CRM Integration with Gmail and Calendar
Applcation CRM lets sales representatives see their Gmail emails and Google Calendar events directly inside the CRM, without giving the CRM their (sale users) Google passwords.
- User logs in to CRM
- The sales rep opens the CRM dashboard.
- CRM asks for permission to access Gmail/Calendar
- The CRM redirects the user to Google’s OAuth2 authorization endpoint.
- User sees a consent screen: “CRM wants to read your emails and events”.
- User grants consent
- Google issues an access token (and optionally a refresh token).
- The access token has limited scope: e.g.,
gmail.readonly,calendar.readonly.
- CRM calls Google APIs on behalf of the user
- CRM uses the access token to fetch the user’s emails and calendar events.
- Emails appear in the CRM dashboard, without ever knowing the user’s Google password.
- Token expiration and refresh
- When the access token expires, the CRM uses the refresh token to get a new one. No user interaction is required for this.
- When the refresh token is expired, the UI will prompt user to authenticate against Google again.
Login with Google
Applcation CRM lets sales representatives login using their own Google account.
- User clicks "Sign in with Google" button
- Google Identity Services (GIS) library handles the authentication
- User authenticates with Google and grants consent
- Google returns an ID Token (JWT) to the frontend
- Frontend sends the ID Token to the backend
- Backend validates the ID Token using Google's public keys
- Backend extracts user info (email, name) from the token
- Backend creates/finds the user and issues a JWT session token
- User is logged into the CRM
The application implements the Authorization Code flow:
- User clicks "Connect Google Account"
- Redirected to Google's authorization server
- User grants permissions
- Google redirects back with authorization code
- Backend exchanges code for access and refresh tokens
- Tokens are stored securely and used for API calls
- Refresh tokens automatically handle token expiration
This application also supports "Login with Google" using OpenID Connect, which is an identity layer built on top of OAuth2.
OpenID Connect (OIDC) extends OAuth2 to provide:
- Authentication (verifying who the user is) in addition to OAuth2's authorization
- ID Token: A JWT containing user identity information (email, name, profile picture). The CRM uses this information to create an user in the system.
| Feature | OAuth2 | OpenID Connect |
|---|---|---|
| Purpose | Authorization (access to resources) | Authentication (user identity) |
| Token Type | Access Token | ID Token + Access Token |
| User Info | Not standardized | Standardized claims (email, name, etc.) |
| Use Case | "Access my Gmail" | "Login with Google" |
The Google ID Token contains standardized claims:
sub: Unique user identifieremail: User's email addressemail_verified: Whether email is verifiedname: User's full namegiven_name: First namefamily_name: Last namepicture: Profile picture URLiat: Issued at timestampexp: Expiration timestamp
export const environment = {
googleClientId: 'YOUR_GOOGLE_CLIENT_ID'
};{
"Google": {
"ClientId": "YOUR_GOOGLE_CLIENT_ID"
}
}- Go to Google Cloud Console
- Create a new project or select existing one
- Enable Gmail API and Google Calendar API
- Create OAuth 2.0 credentials:
- Application type: Web application
- Authorized redirect URIs:
https://localhost:7001/api/google/callback
- Note down the Client ID and Client Secret
-
Update
appsettings.jsonwith your Google OAuth2 credentials:{ "Google": { "ClientId": "YOUR_GOOGLE_CLIENT_ID", "ClientSecret": "YOUR_GOOGLE_CLIENT_SECRET", "RedirectUri": "https://localhost:7001/api/google/callback" } } -
Ensure PostgreSQL connection string is correct in
appsettings.json
The application uses Entity Framework Core migrations for database schema management.
cd src/backend/OpenMind.CRM.Infrastructure
dotnet ef migrations add MigrationName --startup-project ../OpenMind.CRM.API
dotnet ef database update --startup-project ../OpenMind.CRM.APIcd src/backend/OpenMind.CRM.API
dotnet restore
dotnet runThe API will be available at https://localhost:7001
cd src/frontend
npm install
npm startThe Angular app will be available at http://localhost:4200
- Register/Login: Create a new account or login with existing credentials
- Connect Google Account: Click "Connect Google Account" to authorize Gmail and Calendar access
- View Dashboard: Access your emails and calendar events directly in the CRM interface
This project is for educational and demonstration purposes.




