TeslaAuth 3.3.0
dotnet add package TeslaAuth --version 3.3.0
NuGet\Install-Package TeslaAuth -Version 3.3.0
<PackageReference Include="TeslaAuth" Version="3.3.0" />
<PackageVersion Include="TeslaAuth" Version="3.3.0" />
<PackageReference Include="TeslaAuth" />
paket add TeslaAuth --version 3.3.0
#r "nuget: TeslaAuth, 3.3.0"
#:package TeslaAuth@3.3.0
#addin nuget:?package=TeslaAuth&version=3.3.0
#tool nuget:?package=TeslaAuth&version=3.3.0
TeslaAuth library for C# / .NET
Helper library to authenticate to Tesla's API, enabling you to build apps that interact with Tesla's cars and energy products.
Works with the new Fleet API. Note that the Owner API is now deprecated.
This code was originally based on Christian P's work in the TeslaLogger tool.
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
Supported platforms
The library is compiled using .NET Standard 2.0, and can be used by any flavour of .NET that supports this, including .NET, .NET Core, .NET Framework, Mono, UWP and Xamarin.
Sample Apps
This repo includes three samples:
- A WPF sample that demonstrates a native client authentication with an embedded iframe (only runs on Windows)
- A console app that launches the system browser to complete authentication - low tech but simple (should work across platforms)
- An ASP.NET Core app that demonstates web authentication (should work across platforms)
The WPF sample can be used with the Fleet API; you need to supply your own Fleet API keys. You can use any Redirect URL (doesn't even need to be real, but it must match what you configured in the Tesla console)
The console and web sample only works with the Fleet API, and you need to supply your own Fleet API keys. You must use a Redirect Redirect URL that matches the one configured for your app. For the Console sample it doesn't matter what this is, but for the web sample it must the sample website's host, port and path.
Usage
To authenticate users for the Tesla API, you need to show the Tesla sign in UI in a browser (system or embedded). Once the user has authenticated, the tokens are posted back to your page or app.
The steps to use this library are:
- Initialise a
TeslaAuthHelper
instance - Call
authHelper.GetLoginUrlForBrowser()
to generate the login URL - Show the returned URL in the system browser or your app's integrated browser
- Monitor the browser until you see a request for a URL containing the your redirect URL, or if you're building a website, implement the logic directly on the redirect URL
- Grab the entire URL (it contains a query string) and pass it to
authHelper.GetTokenAfterLoginAsync(...)
- This will return a
Tokens
object containing an Access and Refresh token - When the token expires, call
authHelper.RefreshTokenAsync(...)
to get a new one without needing a complete login flow.
Fleet API Authentication
The Fleet API is Tesla's new, officially supported API for third party developers. In order to use it, you need to first register for an account and then register an app to get a Client ID and other details. You must also complete additional onboarding steps as described at developer.tesla.com.
To use the Fleet API, you can initialise a TeslaAuth
instance passing the region
, clientId
, clientSecret
, redirectUri
and
scope
parameters.
The values you use must match the ones configured in the Tesla developer portal.
Calling APIs
Once you have obtained a token from TeslaAuth, you can pass it to the Fleet API as a Bearer token in the Authorization
header. This library does not assist with calling the Tesla APIs; it's only for authentication.
Contributions
Contributions to this library are welcome. If you want to show your appreciation you can also support me on Ko-Fi.
Product | Versions 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. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.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. |
-
.NETStandard 2.0
- System.Text.Json (>= 9.0.0)
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.3.0 | 277 | 7/26/2025 |
3.2.1 | 2,155 | 11/26/2024 |
3.2.0 | 1,907 | 2/24/2024 |
3.1.0 | 488 | 1/26/2024 |
3.0.1 | 841 | 10/21/2023 |
3.0.0 | 447 | 10/18/2023 |
2.3.0 | 3,547 | 2/17/2023 |
2.2.0 | 1,208 | 3/23/2022 |
2.1.0 | 7,041 | 6/2/2021 |
2.0.0 | 718 | 6/1/2021 |
1.0.0-preview.2 | 332 | 3/16/2021 |
1.0.0-preview.1 | 293 | 3/1/2021 |
Replace Newtonsoft dependency with System.Text.Json
Fix client id for refresh flow