I am getting stuck at a point.
Situation:
We use Firebase Authentication in Mobile App IOS/Android and Action On Google (Smart Home). along side we use Firebase Function to handle request.
Problem:
Account linking on Action on google is my problem. however my authentication URL works perfectly and able to send back data successfully. but when it calls token url we get the problem here.
As, I said we use Firebase Authentication, we don't know how to fetch Access token and Refresh token from Firebase to send back to Google Home.
Here is my token code below, i just send constant token right now, i have no idea how to obtain Access token, please help, i would be really thankful to you.
Token URL Firebase Function:
export const token = functions.https.onRequest(async (request, response) => {
//admin.auth().getUser(response)
const grantType = request.query.grant_type ?
request.query.grant_type : request.body.grant_type;
const secondsInDay = 86400; // 60 * 60 * 24
const HTTP_STATUS_OK = 200;
console.log(`Grant type ${grantType}`);
const user = admin.auth().getUser(request.body.code);
user.getIdToken(true).then(function(idToken) {
}).catch(function(error) {
});
console.log(request.body.client_id);
console.log('test');
console.log(request.body.client_secret);
let obj = {};
if (grantType === 'authorization_code') {
obj = {
token_type: 'bearer',
access_token: 'jkljkhasdjhjhkdhasdsd',
refresh_token: 'nkjcajkguiahdilawjd,bcjkbakdjhdlasd',
expires_in: secondsInDay,
};
} else if (grantType === 'refresh_token') {
obj = {
token_type: 'bearer',
access_token: 'njkhasiumnabkdukchaskjhkhad',
expires_in: secondsInDay,
};
}
response.status(HTTP_STATUS_OK)
.json(obj);
});