TeslaAuth 2.3.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package TeslaAuth --version 2.3.0
NuGet\Install-Package TeslaAuth -Version 2.3.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TeslaAuth" Version="2.3.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add TeslaAuth --version 2.3.0
#r "nuget: TeslaAuth, 2.3.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install TeslaAuth as a Cake Addin
#addin nuget:?package=TeslaAuth&version=2.3.0

// Install TeslaAuth as a Cake Tool
#tool nuget:?package=TeslaAuth&version=2.3.0

TeslaAuth library for C# / .NET Core

Helper library to authenticate to Tesla Owner API.

Includes support for MFA.

This code is heavily based on Christian P's work in the TeslaLogger tool. My changes were largely to make it reusable.

Thanks also to Tim Dorr for his work in documenting the new API, and Ramon Smits for his contributions to this library.

Install

The package is available via NuGet with the package name TeslaAuth.

Install-Package TeslaAuth

There are two ways of using this library as described below.

Browser-assisted Example

Probably the most reliable way of using the library is to integrate a WebView into your application and have it show Tesla's login UI. This approach should be resilient to certain changes on Tesla's side, such as when they randomly decide to include (and later remove) a CAPTCHA on the login page. Since Tesla incorporated a CAPTCHA on their login page, it is no longer possible to authenticate using your own UI.

The Test.WPF project demonstrates a complete login and refresh flow. The sample only runs on Windows, but the library itself is cross platform (e.g. works on Xamarin).

The steps to use this approach are as follows:

  1. Initialise a TeslaAuthHelper instance
  2. Call authHelper.GetLoginUrlForBrowser() to generate the login URL
  3. Show the returned URL in your app's integrated browser
  4. Monitor the browser until you see a request for a URL containing the string "void/callback"
  5. Grab the entire URL (it contains a query string) and pass it to authHelper.GetTokenAfterLoginAsync(...)
  6. This will return a Tokens object containing an Access and Refresh token
  7. When the token expires, call authHelper.RefreshTokenAsync(...) to get a new one without needing a complete login flow.

Console Example

The other way to use the library is to build your own login UI. The library allows you to capture the user's email address, password and (if configured) multi-factor authentication code and send these directly to Tesla to obtain tokens. This approach works only when there is no CAPTCHA on the login page (it may or may not return).

The Test.Console project demonstrates a login and refresh flow using this approach.

The steps to use this approach are as follows:

  1. Initialise a TeslaAuthHelper instance
  2. Call `authHelper.Authenticate(...) with the user's credentials to obtain the tokens
  3. When the token expires, call authHelper.RefreshTokenAsync(...) to get a new one without needing a complete login flow.
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.2.0 316 2/24/2024
3.1.0 423 1/26/2024
3.0.1 743 10/21/2023
3.0.0 379 10/18/2023
2.3.0 3,212 2/17/2023
2.2.0 1,094 3/23/2022
2.1.0 4,750 6/2/2021
2.0.0 601 6/1/2021
1.0.0-preview.2 236 3/16/2021
1.0.0-preview.1 196 3/1/2021

New version to support web based UI flow