{"version":3,"file":"line.mjs","names":[],"sources":["../../../../src/plugins/generic-oauth/providers/line.ts"],"sourcesContent":["import type { OAuth2Tokens, OAuth2UserInfo } from \"@better-auth/core/oauth2\";\nimport { betterFetch } from \"@better-fetch/fetch\";\nimport { decodeJwt } from \"jose\";\nimport type { BaseOAuthProviderOptions, GenericOAuthConfig } from \"../index\";\n\nexport interface LineOptions extends BaseOAuthProviderOptions {\n\t/**\n\t * Unique provider identifier for this LINE channel.\n\t * Use different providerIds for different countries/channels (e.g., \"line-jp\", \"line-th\", \"line-tw\").\n\t * @default \"line\"\n\t */\n\tproviderId?: string;\n}\n\ninterface LineIdTokenPayload {\n\tiss: string;\n\tsub: string;\n\taud: string;\n\texp: number;\n\tiat: number;\n\tname?: string;\n\tpicture?: string;\n\temail?: string;\n\tamr?: string[];\n\tnonce?: string;\n}\n\ninterface LineUserInfo {\n\tsub: string;\n\tname?: string;\n\tpicture?: string;\n\temail?: string;\n}\n\n/**\n * LINE OAuth provider helper\n *\n * LINE requires separate channels for different countries (Japan, Thailand, Taiwan, etc.).\n * Each channel has its own clientId and clientSecret. To support multiple countries,\n * call this function multiple times with different providerIds and credentials.\n *\n * @example\n * ```ts\n * import { genericOAuth, line } from \"better-auth/plugins/generic-oauth\";\n *\n * export const auth = betterAuth({\n *   plugins: [\n *     genericOAuth({\n *       config: [\n *         // Japan channel\n *         line({\n *           providerId: \"line-jp\",\n *           clientId: process.env.LINE_JP_CLIENT_ID,\n *           clientSecret: process.env.LINE_JP_CLIENT_SECRET,\n *         }),\n *         // Thailand channel\n *         line({\n *           providerId: \"line-th\",\n *           clientId: process.env.LINE_TH_CLIENT_ID,\n *           clientSecret: process.env.LINE_TH_CLIENT_SECRET,\n *         }),\n *         // Taiwan channel\n *         line({\n *           providerId: \"line-tw\",\n *           clientId: process.env.LINE_TW_CLIENT_ID,\n *           clientSecret: process.env.LINE_TW_CLIENT_SECRET,\n *         }),\n *       ],\n *     }),\n *   ],\n * });\n * ```\n */\nexport function line(options: LineOptions): GenericOAuthConfig {\n\tconst defaultScopes = [\"openid\", \"profile\", \"email\"];\n\tconst authorizationUrl = \"https://access.line.me/oauth2/v2.1/authorize\";\n\tconst tokenUrl = \"https://api.line.me/oauth2/v2.1/token\";\n\tconst userInfoUrl = \"https://api.line.me/oauth2/v2.1/userinfo\";\n\n\tconst getUserInfo = async (\n\t\ttokens: OAuth2Tokens,\n\t): Promise<OAuth2UserInfo | null> => {\n\t\tlet profile: LineUserInfo | LineIdTokenPayload | null = null;\n\n\t\tif (tokens.idToken) {\n\t\t\ttry {\n\t\t\t\tprofile = decodeJwt(tokens.idToken) as LineIdTokenPayload;\n\t\t\t} catch {\n\t\t\t\t// If ID token decoding fails, fall back to UserInfo endpoint\n\t\t\t}\n\t\t}\n\n\t\tif (!profile) {\n\t\t\tconst { data, error } = await betterFetch<LineUserInfo>(userInfoUrl, {\n\t\t\t\theaders: {\n\t\t\t\t\tAuthorization: `Bearer ${tokens.accessToken}`,\n\t\t\t\t},\n\t\t\t});\n\n\t\t\tif (error || !data) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\tprofile = data;\n\t\t}\n\n\t\tif (!profile) {\n\t\t\treturn null;\n\t\t}\n\n\t\treturn {\n\t\t\tid: profile.sub,\n\t\t\tname: profile.name,\n\t\t\temail: profile.email,\n\t\t\timage: profile.picture,\n\t\t\temailVerified: false,\n\t\t};\n\t};\n\n\treturn {\n\t\tproviderId: options.providerId ?? \"line\",\n\t\tauthorizationUrl,\n\t\ttokenUrl,\n\t\tuserInfoUrl,\n\t\tclientId: options.clientId,\n\t\tclientSecret: options.clientSecret,\n\t\tscopes: options.scopes ?? defaultScopes,\n\t\tredirectURI: options.redirectURI,\n\t\tpkce: options.pkce,\n\t\tdisableImplicitSignUp: options.disableImplicitSignUp,\n\t\tdisableSignUp: options.disableSignUp,\n\t\toverrideUserInfo: options.overrideUserInfo,\n\t\tgetUserInfo,\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyEA,SAAgB,KAAK,SAA0C;CAC9D,MAAM,gBAAgB;EAAC;EAAU;EAAW;EAAQ;CACpD,MAAM,mBAAmB;CACzB,MAAM,WAAW;CACjB,MAAM,cAAc;CAEpB,MAAM,cAAc,OACnB,WACoC;EACpC,IAAI,UAAoD;AAExD,MAAI,OAAO,QACV,KAAI;AACH,aAAU,UAAU,OAAO,QAAQ;UAC5B;AAKT,MAAI,CAAC,SAAS;GACb,MAAM,EAAE,MAAM,UAAU,MAAM,YAA0B,aAAa,EACpE,SAAS,EACR,eAAe,UAAU,OAAO,eAChC,EACD,CAAC;AAEF,OAAI,SAAS,CAAC,KACb,QAAO;AAGR,aAAU;;AAGX,MAAI,CAAC,QACJ,QAAO;AAGR,SAAO;GACN,IAAI,QAAQ;GACZ,MAAM,QAAQ;GACd,OAAO,QAAQ;GACf,OAAO,QAAQ;GACf,eAAe;GACf;;AAGF,QAAO;EACN,YAAY,QAAQ,cAAc;EAClC;EACA;EACA;EACA,UAAU,QAAQ;EAClB,cAAc,QAAQ;EACtB,QAAQ,QAAQ,UAAU;EAC1B,aAAa,QAAQ;EACrB,MAAM,QAAQ;EACd,uBAAuB,QAAQ;EAC/B,eAAe,QAAQ;EACvB,kBAAkB,QAAQ;EAC1B;EACA"}