Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to have the refresh token?

I need to use Google Play Android API, i follow a lot of instructions to be connected with the API but I block at one.(Authorization documentation) Exactly at the step 4 when they say:

Sending a Post with this code:

grant_type=authorization_code

code=<the code from the previous step>
client_id=<the client ID token created in the APIs Console>
client_secret=<the client secret corresponding to the client ID>
redirect_uri=<the URI registered with the client ID>`

I specify i use serverless and node, how can I do to have my refresh token in https://accounts.google.com/o/oauth2/token please ?

Thank's a lot and sry for my english ^^.


Sry for this oversight, my serverless it’s just that

#serverless.yml
service: scrapper-app


provider:
  name: aws
  runtime: nodejs8.10
  region: eu-west-3

functions:
  app:
    handler: index.handler
    events:
      - http: ANY /
      - http: 'ANY {proxy+}'

and my js it’s just that too:


//index.js

const serverless = require('serverless-http');
const express = require('express')
const app = express()

//API

const { google } = require('googleapis');
const oauth2Client = new google.auth.OAuth2(
    IDCLient,
    Secret,
    'https://accounts.google.com/o/oauth2/auth',
);

const scopes = 'https://www.googleapis.com/auth/androidpublisher';

const url = oauth2Client.generateAuthUrl({
    access_type: 'offline',
    scope: scopes
)}


// GET
app.get('/', function (req, res) {
    res.send('Scrapper Rs!');
})



module.exports.handler = serverless(app);

I really dont know how can i do http-post using node and serverless, i succeed with a database (with curl) but not post to an url.

like image 843
Jordan Chapuis Avatar asked Dec 31 '25 21:12

Jordan Chapuis


1 Answers

I didn't used Google Authentication. But I think you need to use access_type = offline

access_type Recommended. Indicates whether your application can refresh access tokens when the user is not present at the browser. Valid parameter values are online, which is the default value, and offline.

Set the value to offline if your application needs to refresh access tokens when the user is not present at the browser. This is the method of refreshing access tokens described later in this document. This value instructs the Google authorization server to return a refresh token and an access token the first time that your application exchanges an authorization code for tokens.

To set this value in PHP, call the setAccessType function:

$client->setAccessType('offline');

Source: https://developers.google.com/identity/protocols/OAuth2WebServer

like image 78
gorlok Avatar answered Jan 03 '26 12:01

gorlok



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!