Giter Club home page Giter Club logo

Comments (3)

fredli74 avatar fredli74 commented on June 28, 2024

There's no built-in function for refreshing a token in the HTML page. But if you run it locally with node.js it's super easy making your own, just using the cleaned-up teslaAuth.js library I added in the latest commit.

Clone or download the repository. Then create a refresh.js file in the root (next to the teslaAuth.js file), just containing something like this.

const teslaAuth = require("./teslaAuth");

const token = teslaAuth
    .refreshToken("<<<YOUR REFRESH TOKEN>>>")
    .then(t => console.log(t))

Run it with node refresh.js

The refresh call is a simple POST to the Tesla server. You can just curl it if you like.

curl --header "Content-Type: application/json" --data '{
 "grant_type":"refresh_token",
 "scope":"openid email offline_access",
 "client_id":"ownerapi",
 "refresh_token":"<<<YOUR REFRESH TOKEN>>>"
}' https://auth.tesla.com/oauth2/v3/token

from fetch-tesla-token.

fredli74 avatar fredli74 commented on June 28, 2024

The teslaAuth.js file is all you need from my repository if you want to put the function in your own project. Just copy that single file and then you can use the authenticate, refreshToken, and ownerapiToken functions. They're all documented inside the source.

/**
* Authenticate with Tesla OAuth 2.0 authentication server (v3)
*
* @export
* @throws On any encountered error
* @param {string} identity - Tesla account email address
* @param {string} credential - Tesla account password
* @param {string|undefined} passcode - Multi-Factor Authentication passcode (optional)
* @returns {Object} Returns the Tesla server token response
*/
async function authenticate(identity, credential, passcode) {

/**
* Obtain a new authentication token from a refresh_token
*
* @param {string} refresh_token - refresh_token previously collected from the Tesla authentication API
* @returns {Object} Returns the Tesla server token response
*/
async function refreshToken(refresh_token) {

/**
* Exchange an authentication access_token for a owner-api access_token
*
* @param {string} bearerToken - access_token part of the authentication token (v3)
* @returns {Object} Returns the Tesla server token response
*/
async function ownerapiToken(bearerToken) {

from fetch-tesla-token.

IMgoRt avatar IMgoRt commented on June 28, 2024

The teslaAuth.js file is all you need from my repository if you want to put the function in your own project. Just copy that single file and then you can use the authenticate, refreshToken, and ownerapiToken functions. They're all documented inside the source.

/**
* Authenticate with Tesla OAuth 2.0 authentication server (v3)
*
* @export
* @throws On any encountered error
* @param {string} identity - Tesla account email address
* @param {string} credential - Tesla account password
* @param {string|undefined} passcode - Multi-Factor Authentication passcode (optional)
* @returns {Object} Returns the Tesla server token response
*/
async function authenticate(identity, credential, passcode) {

/**
* Obtain a new authentication token from a refresh_token
*
* @param {string} refresh_token - refresh_token previously collected from the Tesla authentication API
* @returns {Object} Returns the Tesla server token response
*/
async function refreshToken(refresh_token) {

/**
* Exchange an authentication access_token for a owner-api access_token
*
* @param {string} bearerToken - access_token part of the authentication token (v3)
* @returns {Object} Returns the Tesla server token response
*/
async function ownerapiToken(bearerToken) {

That's great, thanks for taking the time to reply, I'll try it out in the morning (01:11 here)

from fetch-tesla-token.

Related Issues (4)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.