MCPcopy
hub / github.com/parse-community/parse-server / getAccessTokenFromCode

Method getAccessTokenFromCode

src/Adapters/Auth/line.js:74–113  ·  view source on GitHub ↗
(authData)

Source from the content-addressed store, hash-verified

72 }
73
74 async getAccessTokenFromCode(authData) {
75 if (!authData.code) {
76 throw new Parse.Error(
77 Parse.Error.OBJECT_NOT_FOUND,
78 'Line auth is invalid for this user.'
79 );
80 }
81
82 const tokenUrl = 'https://api.line.me/oauth2/v2.1/token';
83 const response = await fetch(tokenUrl, {
84 method: 'POST',
85 headers: {
86 'Content-Type': 'application/x-www-form-urlencoded',
87 },
88 body: new URLSearchParams({
89 client_id: this.clientId,
90 client_secret: this.clientSecret,
91 grant_type: 'authorization_code',
92 redirect_uri: authData.redirect_uri,
93 code: authData.code,
94 }),
95 });
96
97 if (!response.ok) {
98 throw new Parse.Error(
99 Parse.Error.OBJECT_NOT_FOUND,
100 `Failed to exchange code for token: ${response.statusText}`
101 );
102 }
103
104 const data = await response.json();
105 if (data.error) {
106 throw new Parse.Error(
107 Parse.Error.OBJECT_NOT_FOUND,
108 data.error_description || data.error
109 );
110 }
111
112 return data.access_token;
113 }
114
115 async getUserFromAccessToken(accessToken) {
116 const userApiUrl = 'https://api.line.me/v2/profile';

Callers

nothing calls this directly

Calls 1

fetchFunction · 0.50

Tested by

no test coverage detected