LINE and Google Account Linking with Secure OAuth2 Flow - n8n Workflow

Use this comprehensive n8n workflow to automate secure account linking between LINE Official Accounts and Google accounts using the full OAuth2 authorization flow.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Developers managing services that integrate user identities across LINE and Google.
Technical marketers who need robust, automated authentication methods.
Users seeking advanced examples of n8n templates for handling complex, multi-stage authorization protocols.
Engineers looking to implement secure identity federation without writing complex backend code using this powerful n8n workflow.

Overview

Managing user identity across multiple platforms requires robust and secure mechanisms. This specialized n8n workflow addresses the complexity of linking users from a LINE Official Account (OA) to their corresponding Google profile using the OAuth2 protocol. It demonstrates how the n8n automation platform can orchestrate intricate API interactions.

The n8n workflow is divided into two phases, ensuring that the critical step of identity verification (using the LINE User ID as the OAuth state parameter) is handled securely. This n8n automation template provides a production-ready solution for enhancing user services by integrating external identity providers, showcasing the immense power and flexibility of the n8n node library.

How it Works

This n8n automation consists of two main execution branches, each initiated by a unique n8n trigger webhook:

Phase 1: Authorization Initiation (LINE Follow Event)


  1. The LINE Webhook n8n trigger receives a POST request when a user interacts with the LINE OA (e.g., adding as a friend).

  2. The If Follow Event n8n node checks the incoming payload to ensure the trigger is specifically a follow event.

  3. The Create Google Auth URL n8n node dynamically generates the Google OAuth URL. Crucially, it embeds the LINE user ID into the state parameter, which is essential for securely identifying the user during the callback.

  4. The Send Auth Link to LINE n8n node uses the LINE Messaging API to reply to the user, providing a welcome message and the unique authentication link.

Phase 2: Token Exchange and Completion (Google Auth Callback)


  1. The user authenticates with Google and is redirected to the Google Auth Callback n8n trigger endpoint, carrying the authorization code and the original LINE User ID in the state parameter.

  2. The Get Google Access Token n8n node performs an HTTP POST request to Google, exchanging the received authorization code for a valid access token.

  3. The Get Google User Info n8n node uses the acquired token to fetch the user's profile data (such as email and name) from Google's user info endpoint.

  4. The Send Completion Message to LINE n8n node securely sends a confirmation message to the LINE user ID (retrieved from the state parameter), confirming the successful linkage and displaying the fetched email.

  5. Finally, the Redirect to LINE OA n8n node performs a 302 redirect, guiding the user's browser back to the LINE Official Account chat, providing a seamless conclusion to the n8n workflow.

Installation Guide

To deploy and utilize this advanced n8n workflow, follow these setup steps:


  1. Import the n8n Template: Copy the provided JSON and import it into your n8n instance via the Workflows section. This constitutes a complete n8n workflow structure.

  2. External Setup (LINE & Google): Ensure you have configured your LINE Messaging API channel and established OAuth 2.0 Credentials in Google Cloud Platform (GCP).

  3. Webhook Endpoints: Activate the n8n workflow to generate the two required webhook URLs. Set the LINE Webhook URL in the LINE Developer Console and register the Google Auth Callback URL as an Authorized Redirect URI in GCP.

  4. Credential Configuration: Create a Header Auth credential in n8n for LINE using your Channel Access Token (e.g., Header Name: Authorization, Value: Bearer YOURTOKEN).

  5. Placeholder Replacement: This n8n workflow requires manual updates for sensitive data. Edit the following n8n nodes and replace all placeholder text (YOURGOOGLECLIENTID, YOURGOOGLECLIENTSECRET, YOURN8NWEBHOOKURLFORGOOGLE, etc.) with your actual credentials and URLs:

Create Google Auth URL
Get Google Access Token
* Redirect to LINE OA

  1. Activation: Once all configurations and custom values are set within the n8n workflow, activate the automation to begin listening for the LINE n8n trigger event.

Node Details

LINE Webhook (n8n trigger): The primary n8n trigger for the initiation sequence, listening for incoming events from the LINE Messaging API via a POST request.
If Follow Event (n8n node): A logic node ensuring the n8n workflow only proceeds if the event is a user 'follow', preventing unnecessary execution for other message types.
Create Google Auth URL (Set n8n node): A critical n8n node that uses an expression to construct the secure Google OAuth link, dynamically embedding the LINE User ID into the state parameter.
Send Auth Link to LINE (HTTP Request n8n node): Communicates with the LINE API to send the welcome message and the unique authentication link to the user.
Google Auth Callback (n8n trigger): The secondary n8n trigger, serving as the redirect endpoint for Google after successful user authentication, capturing the OAuth code and state.
Get Google Access Token (HTTP Request n8n node): Manages the core OAuth process by exchanging the authorization code for the necessary access token, demonstrating advanced use of the HTTP Request n8n node.
Get Google User Info (HTTP Request n8n node): Fetches the linked user's profile details (email, name) from Google's API using the newly obtained access token.
Send Completion Message to LINE (HTTP Request n8n node): Sends a final confirmation message back to the user via LINE, referencing the state parameter to identify the correct recipient.


  • Redirect to LINE OA (Respond to Webhook n8n node): Generates a HTTP 302 redirect response, immediately sending the user's browser back to the LINE Official Account after the authentication is finalized.

Related n8n Workflows

Free

Nodes: 6 Nodes
Updated: December 26 2025
View all
Created by
s3110
s3110

Featured*