├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── GM.Api ├── Brands.cs ├── GM.Api.csproj ├── GMClient.cs ├── GMClientBase.cs ├── GMClientNoKey.cs ├── Models │ ├── CommandResponse.cs │ ├── Diagnostic.cs │ ├── HotspotInfo.cs │ ├── Location.cs │ ├── TbtDestination.cs │ └── Vehicle.cs ├── Tokens │ ├── Base32.cs │ ├── JwtTool.cs │ ├── LoginData.cs │ ├── LoginRequest.cs │ └── SortedJsonSerializer.cs └── helpers.cs ├── GM.WindowsUI ├── App.config ├── App.xaml ├── App.xaml.cs ├── BrandWindow.xaml ├── BrandWindow.xaml.cs ├── GM.WindowsUI.csproj ├── LoginWindow.xaml ├── LoginWindow.xaml.cs ├── MainWindow.xaml ├── MainWindow.xaml.cs └── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── GM.sln ├── LICENSE ├── README.md └── _config.yml /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Describe the bug** 11 | A clear and concise description of what the bug is. 12 | 13 | **To Reproduce** 14 | Steps to reproduce the behavior: 15 | 1. Go to '...' 16 | 2. Click on '....' 17 | 3. Scroll down to '....' 18 | 4. See error 19 | 20 | **Expected behavior** 21 | A clear and concise description of what you expected to happen. 22 | 23 | **Screenshots** 24 | If applicable, add screenshots to help explain your problem. 25 | 26 | **Desktop (please complete the following information):** 27 | - OS: [e.g. iOS] 28 | - Browser [e.g. chrome, safari] 29 | - Version [e.g. 22] 30 | 31 | **Smartphone (please complete the following information):** 32 | - Device: [e.g. iPhone6] 33 | - OS: [e.g. iOS8.1] 34 | - Browser [e.g. stock browser, safari] 35 | - Version [e.g. 22] 36 | 37 | **Additional context** 38 | Add any other context about the problem here. 39 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | title: '' 5 | labels: '' 6 | assignees: '' 7 | 8 | --- 9 | 10 | **Is your feature request related to a problem? Please describe.** 11 | A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] 12 | 13 | **Describe the solution you'd like** 14 | A clear and concise description of what you want to happen. 15 | 16 | **Describe alternatives you've considered** 17 | A clear and concise description of any alternative solutions or features you've considered. 18 | 19 | **Additional context** 20 | Add any other context or screenshots about the feature request here. 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.suo 8 | *.user 9 | *.userosscache 10 | *.sln.docstates 11 | 12 | # User-specific files (MonoDevelop/Xamarin Studio) 13 | *.userprefs 14 | 15 | # Build results 16 | [Dd]ebug/ 17 | [Dd]ebugPublic/ 18 | [Rr]elease/ 19 | [Rr]eleases/ 20 | x64/ 21 | x86/ 22 | bld/ 23 | [Bb]in/ 24 | [Oo]bj/ 25 | [Ll]og/ 26 | 27 | # Visual Studio 2015/2017 cache/options directory 28 | .vs/ 29 | # Uncomment if you have tasks that create the project's static files in wwwroot 30 | #wwwroot/ 31 | 32 | # Visual Studio 2017 auto generated files 33 | Generated\ Files/ 34 | 35 | # MSTest test Results 36 | [Tt]est[Rr]esult*/ 37 | [Bb]uild[Ll]og.* 38 | 39 | # NUNIT 40 | *.VisualState.xml 41 | TestResult.xml 42 | 43 | # Build Results of an ATL Project 44 | [Dd]ebugPS/ 45 | [Rr]eleasePS/ 46 | dlldata.c 47 | 48 | # Benchmark Results 49 | BenchmarkDotNet.Artifacts/ 50 | 51 | # .NET Core 52 | project.lock.json 53 | project.fragment.lock.json 54 | artifacts/ 55 | **/Properties/launchSettings.json 56 | 57 | # StyleCop 58 | StyleCopReport.xml 59 | 60 | # Files built by Visual Studio 61 | *_i.c 62 | *_p.c 63 | *_i.h 64 | *.ilk 65 | *.meta 66 | *.obj 67 | *.iobj 68 | *.pch 69 | *.pdb 70 | *.ipdb 71 | *.pgc 72 | *.pgd 73 | *.rsp 74 | *.sbr 75 | *.tlb 76 | *.tli 77 | *.tlh 78 | *.tmp 79 | *.tmp_proj 80 | *.log 81 | *.vspscc 82 | *.vssscc 83 | .builds 84 | *.pidb 85 | *.svclog 86 | *.scc 87 | 88 | # Chutzpah Test files 89 | _Chutzpah* 90 | 91 | # Visual C++ cache files 92 | ipch/ 93 | *.aps 94 | *.ncb 95 | *.opendb 96 | *.opensdf 97 | *.sdf 98 | *.cachefile 99 | *.VC.db 100 | *.VC.VC.opendb 101 | 102 | # Visual Studio profiler 103 | *.psess 104 | *.vsp 105 | *.vspx 106 | *.sap 107 | 108 | # Visual Studio Trace Files 109 | *.e2e 110 | 111 | # TFS 2012 Local Workspace 112 | $tf/ 113 | 114 | # Guidance Automation Toolkit 115 | *.gpState 116 | 117 | # ReSharper is a .NET coding add-in 118 | _ReSharper*/ 119 | *.[Rr]e[Ss]harper 120 | *.DotSettings.user 121 | 122 | # JustCode is a .NET coding add-in 123 | .JustCode 124 | 125 | # TeamCity is a build add-in 126 | _TeamCity* 127 | 128 | # DotCover is a Code Coverage Tool 129 | *.dotCover 130 | 131 | # AxoCover is a Code Coverage Tool 132 | .axoCover/* 133 | !.axoCover/settings.json 134 | 135 | # Visual Studio code coverage results 136 | *.coverage 137 | *.coveragexml 138 | 139 | # NCrunch 140 | _NCrunch_* 141 | .*crunch*.local.xml 142 | nCrunchTemp_* 143 | 144 | # MightyMoose 145 | *.mm.* 146 | AutoTest.Net/ 147 | 148 | # Web workbench (sass) 149 | .sass-cache/ 150 | 151 | # Installshield output folder 152 | [Ee]xpress/ 153 | 154 | # DocProject is a documentation generator add-in 155 | DocProject/buildhelp/ 156 | DocProject/Help/*.HxT 157 | DocProject/Help/*.HxC 158 | DocProject/Help/*.hhc 159 | DocProject/Help/*.hhk 160 | DocProject/Help/*.hhp 161 | DocProject/Help/Html2 162 | DocProject/Help/html 163 | 164 | # Click-Once directory 165 | publish/ 166 | 167 | # Publish Web Output 168 | *.[Pp]ublish.xml 169 | *.azurePubxml 170 | # Note: Comment the next line if you want to checkin your web deploy settings, 171 | # but database connection strings (with potential passwords) will be unencrypted 172 | *.pubxml 173 | *.publishproj 174 | 175 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 176 | # checkin your Azure Web App publish settings, but sensitive information contained 177 | # in these scripts will be unencrypted 178 | PublishScripts/ 179 | 180 | # NuGet Packages 181 | *.nupkg 182 | # The packages folder can be ignored because of Package Restore 183 | **/[Pp]ackages/* 184 | # except build/, which is used as an MSBuild target. 185 | !**/[Pp]ackages/build/ 186 | # Uncomment if necessary however generally it will be regenerated when needed 187 | #!**/[Pp]ackages/repositories.config 188 | # NuGet v3's project.json files produces more ignorable files 189 | *.nuget.props 190 | *.nuget.targets 191 | 192 | # Microsoft Azure Build Output 193 | csx/ 194 | *.build.csdef 195 | 196 | # Microsoft Azure Emulator 197 | ecf/ 198 | rcf/ 199 | 200 | # Windows Store app package directories and files 201 | AppPackages/ 202 | BundleArtifacts/ 203 | Package.StoreAssociation.xml 204 | _pkginfo.txt 205 | *.appx 206 | 207 | # Visual Studio cache files 208 | # files ending in .cache can be ignored 209 | *.[Cc]ache 210 | # but keep track of directories ending in .cache 211 | !*.[Cc]ache/ 212 | 213 | # Others 214 | ClientBin/ 215 | ~$* 216 | *~ 217 | *.dbmdl 218 | *.dbproj.schemaview 219 | *.jfm 220 | *.pfx 221 | *.publishsettings 222 | orleans.codegen.cs 223 | 224 | # Including strong name files can present a security risk 225 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 226 | #*.snk 227 | 228 | # Since there are multiple workflows, uncomment next line to ignore bower_components 229 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 230 | #bower_components/ 231 | 232 | # RIA/Silverlight projects 233 | Generated_Code/ 234 | 235 | # Backup & report files from converting an old project file 236 | # to a newer Visual Studio version. Backup files are not needed, 237 | # because we have git ;-) 238 | _UpgradeReport_Files/ 239 | Backup*/ 240 | UpgradeLog*.XML 241 | UpgradeLog*.htm 242 | ServiceFabricBackup/ 243 | *.rptproj.bak 244 | 245 | # SQL Server files 246 | *.mdf 247 | *.ldf 248 | *.ndf 249 | 250 | # Business Intelligence projects 251 | *.rdl.data 252 | *.bim.layout 253 | *.bim_*.settings 254 | *.rptproj.rsuser 255 | 256 | # Microsoft Fakes 257 | FakesAssemblies/ 258 | 259 | # GhostDoc plugin setting file 260 | *.GhostDoc.xml 261 | 262 | # Node.js Tools for Visual Studio 263 | .ntvs_analysis.dat 264 | node_modules/ 265 | 266 | # Visual Studio 6 build log 267 | *.plg 268 | 269 | # Visual Studio 6 workspace options file 270 | *.opt 271 | 272 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 273 | *.vbw 274 | 275 | # Visual Studio LightSwitch build output 276 | **/*.HTMLClient/GeneratedArtifacts 277 | **/*.DesktopClient/GeneratedArtifacts 278 | **/*.DesktopClient/ModelManifest.xml 279 | **/*.Server/GeneratedArtifacts 280 | **/*.Server/ModelManifest.xml 281 | _Pvt_Extensions 282 | 283 | # Paket dependency manager 284 | .paket/paket.exe 285 | paket-files/ 286 | 287 | # FAKE - F# Make 288 | .fake/ 289 | 290 | # JetBrains Rider 291 | .idea/ 292 | *.sln.iml 293 | 294 | # CodeRush 295 | .cr/ 296 | 297 | # Python Tools for Visual Studio (PTVS) 298 | __pycache__/ 299 | *.pyc 300 | 301 | # Cake - Uncomment if you are using it 302 | # tools/** 303 | # !tools/packages.config 304 | 305 | # Tabs Studio 306 | *.tss 307 | 308 | # Telerik's JustMock configuration file 309 | *.jmconfig 310 | 311 | # BizTalk build output 312 | *.btp.cs 313 | *.btm.cs 314 | *.odx.cs 315 | *.xsd.cs 316 | 317 | # OpenCover UI analysis results 318 | OpenCover/ 319 | 320 | # Azure Stream Analytics local run output 321 | ASALocalRun/ 322 | 323 | # MSBuild Binary and Structured Log 324 | *.binlog 325 | 326 | # NVidia Nsight GPU debugger configuration file 327 | *.nvuser 328 | 329 | # MFractors (Xamarin productivity tool) working folder 330 | .mfractor/ 331 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at j8byz4by@gmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | Feel free to issue PRs with improvements, bug fixes, enhancements, etc. 2 | Guidelines: 3 | * Please avoid the inclusion of non-essential third-party libraries. 4 | * Please avoid significant changes to the design without very good reason and include explanation in PR comments. 5 | * Please avoid unnecessary complexity, or style changes that make the code harder to follow without good reason. (e.g. DI, IoC, stupid method names, etc...) 6 | * Please include code docs on all public methods and types, and comments explaining things that aren't obvious 7 | * Be nice 8 | -------------------------------------------------------------------------------- /GM.Api/Brands.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace GM.Api 6 | { 7 | 8 | public enum Brand 9 | { 10 | Opel, 11 | Vauxhall, 12 | Chevrolet, 13 | OnStar, 14 | Cadillac, 15 | Buick, 16 | Gmc 17 | } 18 | 19 | 20 | public static class BrandHelpers 21 | { 22 | 23 | public static string GetDisplayName(this Brand brand) 24 | { 25 | return brand.ToString(); 26 | } 27 | 28 | public static string GetName(this Brand brand) 29 | { 30 | switch (brand) 31 | { 32 | case Brand.Opel: 33 | return "opel"; 34 | case Brand.Vauxhall: 35 | return "vauxhall"; 36 | case Brand.Chevrolet: 37 | return "chevrolet"; 38 | case Brand.OnStar: 39 | return "onstar"; 40 | case Brand.Cadillac: 41 | return "cadillac"; 42 | case Brand.Buick: 43 | return "buick"; 44 | case Brand.Gmc: 45 | return "gmc"; 46 | default: 47 | throw new InvalidOperationException("Unknown Brand"); 48 | } 49 | } 50 | 51 | public static string GetUrl(this Brand brand) 52 | { 53 | switch (brand) 54 | { 55 | case Brand.Opel: 56 | return "https://api.eur.onstar.com/api"; 57 | case Brand.Vauxhall: 58 | return "https://api.eur.onstar.com/api"; 59 | case Brand.Chevrolet: 60 | return "https://api.gm.com/api"; 61 | case Brand.OnStar: 62 | return "https://api.gm.com/api"; 63 | case Brand.Cadillac: 64 | return "https://api.gm.com/api"; 65 | case Brand.Buick: 66 | return "https://api.gm.com/api"; 67 | case Brand.Gmc: 68 | return "https://api.gm.com/api"; 69 | default: 70 | throw new InvalidOperationException("Unknown Brand"); 71 | } 72 | } 73 | 74 | 75 | public static Brand GetBrand(string brandName) 76 | { 77 | var cleanName = brandName.ToLowerInvariant(); 78 | 79 | switch (cleanName) 80 | { 81 | case "opel": 82 | return Brand.Opel; 83 | case "vauxhall": 84 | return Brand.Vauxhall; 85 | case "chevrolet": 86 | return Brand.Chevrolet; 87 | case "onstar": 88 | return Brand.OnStar; 89 | case "cadillac": 90 | return Brand.Cadillac; 91 | case "buick": 92 | return Brand.Buick; 93 | case "gmc": 94 | return Brand.Gmc; 95 | default: 96 | throw new InvalidOperationException("Unknown Brand"); 97 | } 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /GM.Api/GM.Api.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | netstandard2.0 5 | j8byz4by 6 | j8byz4by 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /GM.Api/GMClient.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Threading.Tasks; 5 | using GM.Api.Tokens; 6 | 7 | namespace GM.Api 8 | { 9 | /// 10 | /// GM Client implementation to be used when you have local access to the Client ID and Client Secret 11 | /// 12 | public class GMClient : GMClientBase 13 | { 14 | string _clientId; 15 | JwtTool _jwtTool; 16 | 17 | 18 | public GMClient(string deviceId, Brand brand, string clientId, string clientSecret) : base(deviceId, brand) 19 | { 20 | _clientId = clientId; 21 | _jwtTool = new JwtTool(clientSecret); 22 | } 23 | 24 | protected override async Task EncodeLoginRequest(LoginRequest request) 25 | { 26 | request.ClientId = _clientId; 27 | return _jwtTool.EncodeToken(request); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /GM.Api/GMClientBase.cs: -------------------------------------------------------------------------------- 1 | using GM.Api.Models; 2 | using GM.Api.Tokens; 3 | using JWT; 4 | using JWT.Algorithms; 5 | using Newtonsoft.Json; 6 | using Newtonsoft.Json.Linq; 7 | using System; 8 | using System.Collections.Generic; 9 | using System.Net.Http; 10 | using System.Security.Cryptography; 11 | using System.Text; 12 | using System.Threading.Tasks; 13 | 14 | namespace GM.Api 15 | { 16 | /// 17 | /// Base class API client for GM web services 18 | /// 19 | public abstract class GMClientBase 20 | { 21 | public static int RetryCount { get; set; } = 3; 22 | 23 | //TODO: consistent exception throwing 24 | protected Brand _brand; 25 | protected string _deviceId; 26 | protected string _apiUrl; 27 | 28 | HttpClient _client; 29 | 30 | /// 31 | /// If the current login token has been upgraded 32 | /// Note: it is not known how long this lasts 33 | /// 34 | public bool IsUpgraded { get; private set; } = false; 35 | 36 | bool _isConnected = false; 37 | 38 | /// 39 | /// Contents of the received login token 40 | /// May be populated from a cached token 41 | /// Refreshed automatically 42 | /// 43 | public LoginData LoginData { get; set; } = null; 44 | 45 | /// 46 | /// Active vehicle configuration 47 | /// Must be populated to initiate commands against a car 48 | /// 49 | public Vehicle ActiveVehicle { get; set; } 50 | 51 | 52 | /// 53 | /// Callback called when LoginData is updated 54 | /// Intended to facilitate updating the stored token 55 | /// 56 | public Func TokenUpdateCallback { get; set; } 57 | 58 | 59 | /// 60 | /// Create a new GMClient 61 | /// 62 | /// Device ID (should be in the format of a GUID) 63 | /// One of the supported brands from 64 | public GMClientBase(string deviceId, Brand brand) 65 | { 66 | Setup(deviceId, brand); 67 | } 68 | 69 | void Setup(string deviceId, Brand brand) 70 | { 71 | _brand = brand; 72 | _deviceId = deviceId; 73 | _apiUrl = brand.GetUrl(); 74 | var uri = new Uri(_apiUrl); 75 | _client = CreateClient(uri.Host); 76 | } 77 | 78 | 79 | static HttpClient CreateClient(string host) 80 | { 81 | var client = new HttpClient(new HttpClientHandler() { AllowAutoRedirect = true, AutomaticDecompression = System.Net.DecompressionMethods.GZip }); 82 | 83 | client.DefaultRequestHeaders.AcceptEncoding.SetValue("gzip"); 84 | client.DefaultRequestHeaders.Accept.SetValue("application/json"); 85 | client.DefaultRequestHeaders.AcceptLanguage.SetValue("en-US"); 86 | client.DefaultRequestHeaders.UserAgent.ParseAdd("okhttp/3.9.0"); 87 | client.DefaultRequestHeaders.Host = host; 88 | client.DefaultRequestHeaders.MaxForwards = 10; 89 | client.DefaultRequestHeaders.ExpectContinue = false; 90 | return client; 91 | } 92 | 93 | 94 | protected abstract Task EncodeLoginRequest(LoginRequest request); 95 | 96 | LoginData DecodeLoginData(string token) 97 | { 98 | IJsonSerializer serializer = new SortedJsonSerializer(); 99 | IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder(); 100 | IDateTimeProvider dateTimeProvider = new UtcDateTimeProvider(); 101 | IJwtValidator validator = new JwtValidator(serializer, dateTimeProvider); 102 | var decoder = new JwtDecoder(serializer, validator, urlEncoder); 103 | return decoder.DecodeToObject(token); 104 | } 105 | 106 | 107 | #region Client Helpers 108 | 109 | /// 110 | /// Helper wrapper for SendAsync that handles token updates and retries 111 | /// 112 | /// 113 | /// 114 | /// 115 | async Task SendAsync(HttpRequestMessage request, bool noAuth = false) 116 | { 117 | if (!noAuth) 118 | { 119 | if (LoginData == null) 120 | { 121 | throw new InvalidOperationException("Not Logged in"); 122 | } 123 | if (LoginData.IsExpired) 124 | { 125 | var result = await RefreshToken(); 126 | if (!result) 127 | { 128 | throw new InvalidOperationException("Token refresh failed"); 129 | } 130 | } 131 | } 132 | else 133 | { 134 | request.Headers.Authorization = null; 135 | } 136 | 137 | int attempt = 0; 138 | while (attempt < RetryCount) 139 | { 140 | attempt++; 141 | HttpResponseMessage resp = null; 142 | try 143 | { 144 | resp = await _client.SendAsync(request); 145 | } 146 | catch (Exception ex) 147 | { 148 | //todo: only catch transient errors 149 | //todo: log this 150 | continue; 151 | } 152 | 153 | if (!resp.IsSuccessStatusCode) 154 | { 155 | if (resp.StatusCode == System.Net.HttpStatusCode.Unauthorized || resp.StatusCode == System.Net.HttpStatusCode.Forbidden) 156 | { 157 | var result = await RefreshToken(); 158 | if (!result) 159 | { 160 | throw new InvalidOperationException("Token refresh failed"); 161 | } 162 | continue; 163 | } 164 | else if (resp.StatusCode == System.Net.HttpStatusCode.BadGateway || resp.StatusCode == System.Net.HttpStatusCode.Conflict || resp.StatusCode == System.Net.HttpStatusCode.GatewayTimeout || resp.StatusCode == System.Net.HttpStatusCode.InternalServerError || resp.StatusCode == System.Net.HttpStatusCode.RequestTimeout || resp.StatusCode == System.Net.HttpStatusCode.ResetContent || resp.StatusCode == System.Net.HttpStatusCode.ServiceUnavailable) 165 | { 166 | 167 | var respMessage = (await resp.Content.ReadAsStringAsync()) ?? ""; 168 | int f = 5; 169 | //possible transient errors 170 | //todo: log this 171 | await Task.Delay(500); 172 | continue; 173 | } 174 | else 175 | { 176 | var respMessage = (await resp.Content.ReadAsStringAsync()) ?? ""; 177 | throw new InvalidOperationException("Request error. StatusCode: " + resp.StatusCode.ToString() + ", msg: " + respMessage); 178 | } 179 | } 180 | else 181 | { 182 | return resp; 183 | } 184 | } 185 | //todo: include more info 186 | throw new InvalidOperationException("Request failed too many times"); 187 | } 188 | 189 | 190 | async Task PostAsync(string requestUri, HttpContent content, bool noAuth = false) 191 | { 192 | return await SendAsync(new HttpRequestMessage(HttpMethod.Post, requestUri) { Content = content }, noAuth); 193 | } 194 | 195 | async Task GetAsync(string requestUri, bool noAuth = false) 196 | { 197 | return await SendAsync(new HttpRequestMessage(HttpMethod.Get, requestUri), noAuth); 198 | } 199 | 200 | #endregion 201 | 202 | 203 | /// 204 | /// Connect to vehicle. Must be called before issuing commands 205 | /// 206 | /// 207 | /// 208 | async Task VehicleConnect() 209 | { 210 | if (ActiveVehicle == null) throw new InvalidOperationException("ActiveVehicle must be populated"); 211 | using (var response = await PostAsync(ActiveVehicle.GetCommand("connect").Url, new StringContent("{}", Encoding.UTF8, "application/json"))) 212 | { 213 | if (response.IsSuccessStatusCode) 214 | { 215 | var respString = await response.Content.ReadAsStringAsync(); 216 | var respObj = JsonConvert.DeserializeObject(respString); 217 | if (respObj == null || respObj.CommandResponse == null) return null; 218 | return respObj.CommandResponse; 219 | } 220 | else 221 | { 222 | var error = await response.Content.ReadAsStringAsync(); 223 | return null; 224 | } 225 | } 226 | } 227 | 228 | /// 229 | /// Upgrade the token using OnStar PIN 230 | /// Allows the execution of privileged commands on the vehicle 231 | /// 232 | /// OnStar PIN 233 | /// Success or not 234 | public async Task UpgradeLogin(string onStarPin) 235 | { 236 | var payload = new LoginRequest() 237 | { 238 | //ClientId = _clientId, 239 | DeviceId = _deviceId, 240 | Credential = onStarPin, 241 | CredentialType = "PIN", 242 | Nonce = helpers.GenerateNonce(), 243 | Timestamp = DateTime.UtcNow.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffK") 244 | }; 245 | 246 | //var token = _jwtTool.EncodeToken(payload); 247 | var token = await EncodeLoginRequest(payload); 248 | 249 | using (var response = await PostAsync($"{_apiUrl}/v1/oauth/token/upgrade", new StringContent(token, Encoding.UTF8, "text/plain"))) 250 | { 251 | if (response.IsSuccessStatusCode) 252 | { 253 | IsUpgraded = true; 254 | return true; 255 | } 256 | else 257 | { 258 | var error = await response.Content.ReadAsStringAsync(); 259 | return false; 260 | } 261 | } 262 | } 263 | 264 | 265 | /// 266 | /// Login to the API via Username and Password 267 | /// These credentials are not stored; only exchanged for a token 268 | /// The token is maintained by the client 269 | /// 270 | /// GM account username 271 | /// GM Account password 272 | /// 273 | public async Task Login(string username, string password) 274 | { 275 | var payload = new LoginRequest() 276 | { 277 | //ClientId = _clientId, 278 | DeviceId = _deviceId, 279 | GrantType = "password", 280 | Nonce = helpers.GenerateNonce(), 281 | Password = password, 282 | Scope = "onstar gmoc commerce user_trailer msso", 283 | Timestamp = DateTime.UtcNow.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffK"), 284 | Username = username 285 | }; 286 | 287 | //var token = _jwtTool.EncodeToken(payload); 288 | var token = await EncodeLoginRequest(payload); 289 | 290 | using (var response = await PostAsync($"{_apiUrl}/v1/oauth/token", new StringContent(token, Encoding.UTF8, "text/plain"), true)) 291 | { 292 | string rawResponseToken = null; 293 | 294 | if (response.IsSuccessStatusCode) 295 | { 296 | rawResponseToken = await response.Content.ReadAsStringAsync(); 297 | } 298 | else 299 | { 300 | var error = await response.Content.ReadAsStringAsync(); 301 | } 302 | 303 | if (string.IsNullOrEmpty(rawResponseToken)) 304 | { 305 | return false; 306 | } 307 | 308 | //var loginTokenData = _jwtTool.DecodeTokenToObject(rawResponseToken); 309 | var loginTokenData = DecodeLoginData(rawResponseToken); 310 | 311 | LoginData = loginTokenData; 312 | _client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", LoginData.AccessToken); 313 | 314 | //todo: should this be a copy rather than a reference? 315 | await TokenUpdateCallback?.Invoke(LoginData); 316 | return true; 317 | } 318 | } 319 | 320 | /// 321 | /// Manually refresh access token 322 | /// 323 | /// Success tru or false 324 | public async Task RefreshToken() 325 | { 326 | if (LoginData == null) return false; 327 | 328 | var payload = new LoginRequest() 329 | { 330 | DeviceId = _deviceId, 331 | GrantType = "urn:ietf:params:oauth:grant-type:jwt-bearer", 332 | Nonce = helpers.GenerateNonce(), 333 | Scope = "onstar gmoc commerce user_trailer", 334 | Timestamp = DateTime.UtcNow.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffK"), 335 | Assertion = LoginData.IdToken 336 | }; 337 | 338 | var token = await EncodeLoginRequest(payload); 339 | 340 | using (var response = await PostAsync($"{_apiUrl}/v1/oauth/token", new StringContent(token, Encoding.UTF8, "text/plain"), true)) 341 | { 342 | 343 | string rawResponseToken = null; 344 | 345 | if (response.IsSuccessStatusCode) 346 | { 347 | rawResponseToken = await response.Content.ReadAsStringAsync(); 348 | } 349 | else 350 | { 351 | var error = await response.Content.ReadAsStringAsync(); 352 | } 353 | 354 | if (string.IsNullOrEmpty(rawResponseToken)) 355 | { 356 | return false; 357 | } 358 | 359 | 360 | /*{ 361 | "access_token": , 362 | "token_type": "Bearer", 363 | "expires_in": 1800, 364 | "scope": "user_trailer onstar commerce gmoc role_owner", 365 | "user_info": { 366 | "RemoteUserId": "", 367 | "country": "" 368 | } 369 | }*/ 370 | // Not sure if the scope needs to be updated, as msso has been removed in the refresh request 371 | 372 | var refreshData = DecodeLoginData(rawResponseToken); 373 | 374 | LoginData.AccessToken = refreshData.AccessToken; 375 | LoginData.IssuedAtUtc = refreshData.IssuedAtUtc; 376 | LoginData.ExpiresIn = refreshData.ExpiresIn; 377 | 378 | //should we assume the upgrade status is broken? 379 | 380 | 381 | _client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", LoginData.AccessToken); 382 | 383 | //todo: should this be a copy rather than a reference? 384 | await TokenUpdateCallback?.Invoke(LoginData); 385 | 386 | return true; 387 | } 388 | } 389 | 390 | 391 | 392 | #region Commands 393 | 394 | 395 | /// 396 | /// Submit the initial call for a command 397 | /// NOTE: this will be changing to use the URLs defined in vehicle configuration 398 | /// 399 | /// Vehicle VIN 400 | /// OnStar PIN 401 | /// command name 402 | /// 403 | async Task InitiateCommand(string command, JObject requestParameters) 404 | { 405 | if (ActiveVehicle == null) throw new InvalidOperationException("ActiveVehicle must be populated"); 406 | 407 | var cmdInfo = ActiveVehicle.GetCommand(command); 408 | 409 | if (cmdInfo == null) throw new InvalidOperationException("Unsupported command"); 410 | 411 | if (cmdInfo.IsPrivSessionRequired.GetValueOrDefault()) 412 | { 413 | if (!IsUpgraded) 414 | { 415 | //TODO: need to determine how long an upgrade lasts - do we reset it when refreshing the token? 416 | // Also if the android app saves the PIN, should we save the PIN? 417 | throw new InvalidOperationException("Command requires upgraded login"); 418 | } 419 | } 420 | 421 | if (!_isConnected) 422 | { 423 | await VehicleConnect(); 424 | _isConnected = true; 425 | } 426 | 427 | 428 | JObject reqObj = requestParameters; 429 | 430 | if (reqObj == null) 431 | { 432 | reqObj = new JObject(); 433 | } 434 | 435 | 436 | 437 | using (var response = await PostAsync(cmdInfo.Url, new StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(reqObj), Encoding.UTF8, "application/json"))) 438 | { 439 | if (!response.IsSuccessStatusCode) 440 | { 441 | var error = await response.Content.ReadAsStringAsync(); 442 | //todo: is this needed with the fancy post? 443 | return null; 444 | } 445 | 446 | var commandResult = await response.Content.ReadAsAsync(); 447 | 448 | return commandResult.CommandResponse; 449 | } 450 | } 451 | 452 | 453 | /// 454 | /// Periodically poll the status of a command, only returning after it succeeds or fails 455 | /// 456 | /// statusUrl returned when the command was initiated 457 | /// Response from final poll 458 | async Task WaitForCommandCompletion(string statusUrl) 459 | { 460 | int nullResponseCount = 0; 461 | 462 | while (true) 463 | { 464 | await Task.Delay(5000); 465 | var result = await PollCommandStatus(statusUrl); 466 | if (result == null) 467 | { 468 | nullResponseCount++; 469 | if (nullResponseCount > 5) return null; 470 | } 471 | if ("inProgress".Equals(result.Status, StringComparison.OrdinalIgnoreCase)) continue; 472 | return result; 473 | } 474 | } 475 | 476 | /// 477 | /// Initiate a command and wait for completion, returning the Command Response 478 | /// 479 | /// Command Name 480 | /// Command request parameters 481 | /// Command Response 482 | protected async Task InitiateCommandAndWait(string command, JObject requestParameters) 483 | { 484 | var result = await InitiateCommand(command, requestParameters); 485 | var endStatus = await WaitForCommandCompletion(result.Url); 486 | return endStatus; 487 | } 488 | 489 | 490 | /// 491 | /// Initiate a command and wait for completion, parsing the response for success flag 492 | /// 493 | /// Command Name 494 | /// Command request parameters 495 | /// True or false if the command succeeded 496 | protected async Task InitiateCommandAndWaitForSuccess(string command, JObject requestParameters) 497 | { 498 | var result = await InitiateCommandAndWait(command, requestParameters); 499 | if (result == null) return false; 500 | if ("success".Equals(result.Status, StringComparison.OrdinalIgnoreCase)) 501 | { 502 | return true; 503 | } 504 | else 505 | { 506 | return false; 507 | } 508 | } 509 | 510 | /// 511 | /// Call the status URL for a command 512 | /// 513 | /// 514 | /// 515 | async Task PollCommandStatus(string statusUrl) 516 | { 517 | var response = await GetAsync($"{statusUrl}?units=METRIC"); 518 | 519 | if (response.IsSuccessStatusCode) 520 | { 521 | var result = await response.Content.ReadAsAsync(); 522 | return result.CommandResponse; 523 | } 524 | else 525 | { 526 | return null; 527 | } 528 | } 529 | 530 | 531 | /// 532 | /// Get the list of vehicle configurations for the first 10 vehicles on the account 533 | /// Result of this request is required to use vehicle-specific commands 534 | /// 535 | /// Collection of Vehicle configurations 536 | public async Task> GetVehicles() 537 | { 538 | //these could be parameterized, but we better stick with what the app does 539 | var resp = await GetAsync($"{_apiUrl}/v1/account/vehicles?offset=0&limit=10&includeCommands=true&includeEntitlements=true&includeModules=true"); 540 | 541 | if (resp.IsSuccessStatusCode) 542 | { 543 | var outerResult = await resp.Content.ReadAsAsync(); 544 | if (outerResult.Vehicles != null && outerResult.Vehicles.Vehicle != null && outerResult.Vehicles.Vehicle.Length > 0) 545 | { 546 | return outerResult.Vehicles.Vehicle; 547 | } 548 | } 549 | 550 | return null; 551 | } 552 | 553 | 554 | 555 | 556 | 557 | #endregion 558 | 559 | 560 | #region Command Implementations 561 | 562 | /// 563 | /// Retrieve Diagnostic data for the active vehicle 564 | /// 565 | /// 566 | public async Task GetDiagnostics() 567 | { 568 | var cmdInfo = ActiveVehicle.GetCommand("diagnostics"); 569 | 570 | var reqObj = new JObject() 571 | { 572 | ["diagnosticsRequest"] = new JObject() 573 | { 574 | ["diagnosticItem"] = new JArray(cmdInfo.CommandData.SupportedDiagnostics.SupportedDiagnostic) 575 | } 576 | }; 577 | 578 | var result = await InitiateCommandAndWait("diagnostics", reqObj); 579 | if (result == null) return null; 580 | if ("success".Equals(result.Status, StringComparison.OrdinalIgnoreCase)) 581 | { 582 | return result.Body.DiagnosticResponse; 583 | } 584 | else 585 | { 586 | return null; 587 | } 588 | } 589 | 590 | 591 | /// 592 | /// Issue an arbitrary command 593 | /// 594 | /// Name of the command. Must exists in the vehicle's configuration 595 | /// JSON parameters for the command 596 | /// 597 | public async Task IssueCommand(string commandName, JObject parameters = null) 598 | { 599 | return await InitiateCommandAndWait(commandName, parameters); 600 | } 601 | 602 | /// 603 | /// Lock the active vehicles's doors and wait for completion 604 | /// Privileged Command 605 | /// 606 | /// True or false for success 607 | public async Task LockDoor() 608 | { 609 | 610 | var reqObj = new JObject() 611 | { 612 | ["lockDoorRequest"] = new JObject() 613 | { 614 | ["delay"] = 0 615 | } 616 | }; 617 | 618 | return await InitiateCommandAndWaitForSuccess("lockDoor", reqObj); 619 | } 620 | 621 | 622 | /// 623 | /// Fails when the hotspot is off... 624 | /// Note: the app uses diagnotics that also fail when the hotpot is off 625 | /// 626 | /// 627 | public async Task GetHotspotInfo() 628 | { 629 | var resp = await InitiateCommandAndWait("getHotspotInfo", null); 630 | return resp.Body.HotspotInfo; 631 | } 632 | 633 | 634 | /// 635 | /// Send a turn-by-turn destination to the vehicle 636 | /// Requires both coordinates and address info 637 | /// Vehicle may not respond if turned off or may take a very long time to respond 638 | /// 639 | /// 640 | /// 641 | public async Task SendTBTRoute(TbtDestination destination) 642 | { 643 | var reqObj = new JObject() 644 | { 645 | ["tbtDestination"] = new JObject(destination) 646 | }; 647 | 648 | return await InitiateCommandAndWaitForSuccess("sendTBTRoute", reqObj); 649 | } 650 | 651 | 652 | /// 653 | /// Unlock the active vehicles's doors and wait for completion 654 | /// Privileged Command 655 | /// 656 | /// True or false for success 657 | public async Task UnlockDoor() 658 | { 659 | var reqObj = new JObject() 660 | { 661 | ["unlockDoorRequest"] = new JObject() 662 | { 663 | ["delay"] = 0 664 | } 665 | }; 666 | 667 | return await InitiateCommandAndWaitForSuccess("unlockDoor", reqObj); 668 | } 669 | 670 | /// 671 | /// Remote start the active vehicle and wait for completion 672 | /// Privileged Command 673 | /// 674 | /// True or false for success 675 | public async Task Start() 676 | { 677 | return await InitiateCommandAndWaitForSuccess("start", null); 678 | } 679 | 680 | /// 681 | /// Remote stop the active vehicle and wait for completion 682 | /// Privileged Command 683 | /// 684 | /// True or false for success 685 | public async Task CancelStart() 686 | { 687 | return await InitiateCommandAndWaitForSuccess("cancelStart", null); 688 | } 689 | 690 | 691 | /// 692 | /// Set off remote alarm on the active vehicle and wait for completion 693 | /// Privileged Command 694 | /// 695 | /// True or false for success 696 | public async Task Alert() 697 | { 698 | var reqObj = new JObject() 699 | { 700 | ["alertRequest"] = new JObject() 701 | { 702 | ["action"] = new JArray() { "Honk", "Flash" }, 703 | ["delay"] = 0, 704 | ["duration"] = 1, 705 | ["override"] = new JArray() { "DoorOpen", "IgnitionOn" } 706 | } 707 | }; 708 | 709 | return await InitiateCommandAndWaitForSuccess("alert", reqObj); 710 | } 711 | 712 | /// 713 | /// Stop remote alarm on the active vehicle and wait for completion 714 | /// Privileged Command 715 | /// 716 | /// True or false for success 717 | public async Task CancelAlert() 718 | { 719 | return await InitiateCommandAndWaitForSuccess("cancelAlert", null); 720 | } 721 | 722 | #endregion 723 | 724 | 725 | 726 | } 727 | } 728 | -------------------------------------------------------------------------------- /GM.Api/GMClientNoKey.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Net.Http; 4 | using System.Text; 5 | using System.Threading.Tasks; 6 | using GM.Api.Tokens; 7 | 8 | namespace GM.Api 9 | { 10 | /// 11 | /// GM Client implementation that uses a web service to sign the JWT tokens required for authentication 12 | /// Use this if you do not have access to the Client ID and Client Secret 13 | /// 14 | public class GMClientNoKey : GMClientBase 15 | { 16 | string _tokenSignUrl; 17 | HttpClient _tokenClient = new HttpClient(); 18 | 19 | /// 20 | /// Create new GM Client 21 | /// 22 | /// deviceId = string representation of a GUID 23 | /// API is segmented by brand 24 | /// URL for webservice that will sign JWT tokens (e.g. "https://gmsigner.herokuapp.com/") 25 | public GMClientNoKey(string deviceId, Brand brand, string tokenSignUrl) : base(deviceId, brand) 26 | { 27 | _tokenSignUrl = tokenSignUrl; 28 | } 29 | 30 | protected override async Task EncodeLoginRequest(LoginRequest request) 31 | { 32 | var resp = await _tokenClient.PostAsJsonAsync($"{_tokenSignUrl}?brand={_brand.GetName()}", request); 33 | 34 | if (resp.IsSuccessStatusCode) 35 | { 36 | return await resp.Content.ReadAsStringAsync(); 37 | } 38 | else 39 | { 40 | string errorText = await resp.Content.ReadAsStringAsync(); 41 | throw new InvalidOperationException("Token sign failure: " + errorText); 42 | } 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /GM.Api/Models/CommandResponse.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace GM.Api.Models 7 | { 8 | /// 9 | /// Root object returned by a command request, or a call to a status url 10 | /// 11 | public class CommandRequestResponse 12 | { 13 | /// 14 | /// Inner response 15 | /// 16 | [JsonProperty("commandResponse")] 17 | public CommandResponse CommandResponse { get; set; } 18 | } 19 | 20 | /// 21 | /// Command Response Object 22 | /// 23 | public class CommandResponse 24 | { 25 | /// 26 | /// Timestamp the request was received by the server 27 | /// 28 | [JsonProperty("requestTime")] 29 | public DateTime RequestTime { get; set; } 30 | 31 | /// 32 | /// Timestamp the server completed the request 33 | /// 34 | [JsonProperty("completionTime")] 35 | public DateTime CompletionTime { get; set; } 36 | 37 | /// 38 | /// Status URL to be polled for updates (commands are async) 39 | /// 40 | [JsonProperty("url")] 41 | public string Url { get; set; } 42 | 43 | /// 44 | /// Current status of the command request 45 | /// (e.g. "inProgress", "success") 46 | /// 47 | [JsonProperty("status")] 48 | public string Status { get; set; } //inProgress, success 49 | 50 | /// 51 | /// Probably refers to the type of the response body 52 | /// 53 | [JsonProperty("type")] 54 | public string Type { get; set; } 55 | 56 | /// 57 | /// Response body for commands that include a response (e.g. diagnostics, location) 58 | /// 59 | [JsonProperty("body")] 60 | public ResponseBody Body { get; set; } 61 | 62 | } 63 | 64 | 65 | 66 | /// 67 | /// Response Body 68 | /// Note: this only contains a diagnostic response. there are likely others. 69 | /// 70 | public class ResponseBody 71 | { 72 | /// 73 | /// Populated for diagnostics command 74 | /// 75 | [JsonProperty("diagnosticResponse")] 76 | public DiagnosticResponse[] DiagnosticResponse { get; set; } 77 | 78 | /// 79 | /// populated for location command 80 | /// 81 | [JsonProperty("location")] 82 | public Location Location { get; set; } 83 | 84 | /// 85 | /// placeholder - not yet tested 86 | /// 87 | [JsonProperty("hotspotInfo")] 88 | public HotspotInfo HotspotInfo { get; set; } 89 | 90 | } 91 | 92 | 93 | } 94 | -------------------------------------------------------------------------------- /GM.Api/Models/Diagnostic.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using System.Linq; 5 | using Newtonsoft.Json; 6 | 7 | namespace GM.Api.Models 8 | { 9 | public class DiagnosticResponse 10 | { 11 | [JsonProperty("name")] 12 | public string Name { get; set; } 13 | 14 | [JsonProperty("diagnosticElement")] 15 | public DiagnosticElement[] DiagnosticElement { get; set; } 16 | } 17 | 18 | public class DiagnosticElement 19 | { 20 | [JsonProperty("name")] 21 | public string Name { get; set; } 22 | 23 | [JsonProperty("status")] 24 | public string Status { get; set; } 25 | 26 | [JsonProperty("message")] 27 | public string Message { get; set; } 28 | 29 | [JsonProperty("value")] 30 | public string Value { get; set; } 31 | 32 | [JsonProperty("unit")] 33 | public string Unit { get; set; } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /GM.Api/Models/HotspotInfo.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace GM.Api.Models 6 | { 7 | /// 8 | /// Placeholder 9 | /// 10 | public class HotspotInfo 11 | { 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /GM.Api/Models/Location.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace GM.Api.Models 7 | { 8 | public class Location 9 | { 10 | [JsonProperty("lat")] 11 | public float? Latitude { get; set; } 12 | 13 | [JsonProperty("long")] 14 | public float? Longitude { get; set; } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /GM.Api/Models/TbtDestination.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace GM.Api.Models 7 | { 8 | 9 | public class TbtDestination 10 | { 11 | [JsonProperty("additionalDestinationInfo")] 12 | public AdditionalDestinationInfo AdditionalDestinationInfo { get; set; } 13 | 14 | [JsonProperty("destinationLocation")] 15 | public Location DestinationLocation { get; set; } 16 | } 17 | 18 | public class AdditionalDestinationInfo 19 | { 20 | [JsonProperty("destinationAddress")] 21 | public DestinationAddress DestinationAddress { get; set; } 22 | 23 | [JsonProperty("destinationType")] 24 | public string DestinationType { get; set; } 25 | } 26 | 27 | public class DestinationAddress 28 | { 29 | [JsonProperty("city")] 30 | public string City { get; set; } 31 | 32 | [JsonProperty("country")] 33 | public string Country { get; set; } 34 | 35 | [JsonProperty("state")] 36 | public string State { get; set; } 37 | 38 | [JsonProperty("street")] 39 | public string Street { get; set; } 40 | 41 | [JsonProperty("streetNo")] 42 | public string StreetNo { get; set; } 43 | 44 | [JsonProperty("zipCode")] 45 | public string ZipCode { get; set; } 46 | } 47 | 48 | public class DestinationLocation 49 | { 50 | public void SetLatitude(float value) 51 | { 52 | Latitude = value.ToString("###.#####"); 53 | } 54 | 55 | public void SetLongitude(float value) 56 | { 57 | Longitude = value.ToString("###.#####"); 58 | } 59 | 60 | [JsonProperty("lat")] 61 | public string Latitude { get; set; } 62 | 63 | [JsonProperty("long")] 64 | public string Longitude { get; set; } 65 | } 66 | 67 | 68 | } 69 | -------------------------------------------------------------------------------- /GM.Api/Models/Vehicle.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | 7 | namespace GM.Api.Models 8 | { 9 | 10 | 11 | public class VehiclesResponse 12 | { 13 | [JsonProperty("vehicles")] 14 | public Vehicles Vehicles { get; set; } 15 | } 16 | 17 | public class Vehicles 18 | { 19 | /// 20 | /// Size of the Vehicle array, or full size. One would need to have more than 10 cars to find out... 21 | /// 22 | [JsonProperty("size")] 23 | public string Size { get; set; } 24 | 25 | /// 26 | /// List of vehicles associated with the account 27 | /// Note that there is paging and by default the page size is 10 28 | /// 29 | [JsonProperty("vehicle")] 30 | public Vehicle[] Vehicle { get; set; } 31 | } 32 | 33 | /// 34 | /// Vehicle description 35 | /// 36 | public class Vehicle 37 | { 38 | /// 39 | /// Vehicle VIN 40 | /// 41 | [JsonProperty("vin")] 42 | public string Vin { get; set; } 43 | 44 | /// 45 | /// Vehicle Make 46 | /// 47 | [JsonProperty("make")] 48 | public string Make { get; set; } 49 | 50 | /// 51 | /// Vehicle Model 52 | /// 53 | [JsonProperty("model")] 54 | public string Model { get; set; } 55 | 56 | /// 57 | /// Vehicle Year 58 | /// 59 | [JsonProperty("year")] 60 | public string Year { get; set; } 61 | 62 | /// 63 | /// Vehicle Manufacturer - not sure why this is required... 64 | /// 65 | [JsonProperty("manufacturer")] 66 | public string Manufacturer { get; set; } 67 | 68 | /// 69 | /// (e.g. car, maybe truck) 70 | /// 71 | [JsonProperty("bodyStyle")] 72 | public string BodyStyle { get; set; } 73 | 74 | /// 75 | /// Vehicle cellular / OnStar phone number 76 | /// 77 | [JsonProperty("phone")] 78 | public string Phone { get; set; } 79 | 80 | [JsonProperty("unitType")] 81 | public string UnitType { get; set; } 82 | 83 | [JsonProperty("onstarStatus")] 84 | public string OnStarStatus { get; set; } 85 | 86 | /// 87 | /// Base URL for API calls regarding this vehicle 88 | /// 89 | [JsonProperty("url")] 90 | public string Url { get; set; } 91 | 92 | [JsonProperty("isInPreActivation")] 93 | public bool? IsInPreActivation { get; set; } 94 | 95 | [JsonProperty("insuranceInfo")] 96 | public InsuranceInfo InsuranceInfo { get; set; } 97 | 98 | [JsonProperty("enrolledInContinuousCoverage")] 99 | public bool? EnrolledInContinuousCoverage { get; set; } 100 | 101 | /// 102 | /// Details on supported commands 103 | /// 104 | [JsonProperty("commands")] 105 | public Commands Commands { get; set; } 106 | 107 | /// 108 | /// Details on available modules 109 | /// 110 | [JsonProperty("modules")] 111 | public Modules Modules { get; set; } 112 | 113 | /// 114 | /// Details on available entitlements 115 | /// 116 | [JsonProperty("entitlements")] 117 | public Entitlements Entitlements { get; set; } 118 | 119 | [JsonProperty("propulsionType")] 120 | public string PropulsionType { get; set; } 121 | 122 | 123 | public Command GetCommand(string name) 124 | { 125 | return (from f in Commands.Command where f.Name.Equals(name, StringComparison.Ordinal) select f).FirstOrDefault(); 126 | } 127 | 128 | } 129 | 130 | public class InsuranceInfo 131 | { 132 | [JsonProperty("insuranceAgent")] 133 | public InsuranceAgent InsuranceAgent { get; set; } 134 | } 135 | 136 | public class InsuranceAgent 137 | { 138 | [JsonProperty("phone")] 139 | public Phone Phone { get; set; } 140 | } 141 | 142 | public class Phone 143 | { 144 | } 145 | 146 | public class Commands 147 | { 148 | /// 149 | /// List of commands supported by the vehicle 150 | /// 151 | [JsonProperty("command")] 152 | public Command[] Command { get; set; } 153 | } 154 | 155 | /// 156 | /// Details about a supported command 157 | /// 158 | public class Command 159 | { 160 | /// 161 | /// Command name 162 | /// 163 | [JsonProperty("name")] 164 | public string Name { get; set; } 165 | 166 | /// 167 | /// Description of what the command does 168 | /// 169 | [JsonProperty("description")] 170 | public string Description { get; set; } 171 | 172 | /// 173 | /// API URL to be used for issuing the command 174 | /// This SDK uses this url rather than constructing it 175 | /// 176 | [JsonProperty("url")] 177 | public string Url { get; set; } 178 | 179 | /// 180 | /// True or False if the command requires the token to be upgraded with an OnStar PIN 181 | /// 182 | [JsonProperty("isPrivSessionRequired")] 183 | public bool? IsPrivSessionRequired { get; set; } 184 | 185 | /// 186 | /// For commands with additional data such as diagnostics 187 | /// 188 | [JsonProperty("commandData")] 189 | public CommandData CommandData { get; set; } 190 | } 191 | 192 | public class CommandData 193 | { 194 | [JsonProperty("supportedDiagnostics")] 195 | public SupportedDiagnostics SupportedDiagnostics { get; set; } 196 | } 197 | 198 | public class SupportedDiagnostics 199 | { 200 | /// 201 | /// List of the diagnostic elements that may be requsted for the vehicle 202 | /// 203 | [JsonProperty("supportedDiagnostic")] 204 | public string[] SupportedDiagnostic { get; set; } 205 | } 206 | 207 | public class Modules 208 | { 209 | /// 210 | /// List of modules - not much here 211 | /// 212 | [JsonProperty("module")] 213 | public Module[] Module { get; set; } 214 | } 215 | 216 | public class Module 217 | { 218 | [JsonProperty("moduleType")] 219 | public string ModuleType { get; set; } 220 | 221 | [JsonProperty("moduleCapability")] 222 | public string ModuleCapability { get; set; } 223 | } 224 | 225 | public class Entitlements 226 | { 227 | /// 228 | /// List of entitlements - features and activities vehicles are capable of 229 | /// List contains things the vehicle or account may or may not support 230 | /// Check the Elligible flag 231 | /// 232 | [JsonProperty("entitlement")] 233 | public Entitlement[] Entitlement { get; set; } 234 | } 235 | 236 | /// 237 | /// Details about an Entitlement 238 | /// 239 | public class Entitlement 240 | { 241 | /// 242 | /// ID or name of entitlement 243 | /// 244 | [JsonProperty("id")] 245 | public string Id { get; set; } 246 | 247 | /// 248 | /// True or false if the entitlement is available on this vehicle or account 249 | /// 250 | [JsonProperty("eligible")] 251 | public bool? Eligible { get; set; } 252 | 253 | /// 254 | /// Reason for inelligibility (whether the car is incapable or the owner isn't subscribed) 255 | /// 256 | [JsonProperty("ineligibleReasonCode")] 257 | public string IneligibleReasonCode { get; set; } 258 | 259 | /// 260 | /// True or false if the entitlement can send notifications 261 | /// 262 | [JsonProperty("notificationCapable")] 263 | public bool? NotificationCapable { get; set; } 264 | } 265 | 266 | 267 | } 268 | -------------------------------------------------------------------------------- /GM.Api/Tokens/Base32.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace GM.Api.Tokens 6 | { 7 | /// 8 | /// Base32 Implementation 9 | /// https://stackoverflow.com/a/641437 10 | /// 11 | sealed class Base32 12 | { 13 | 14 | // the valid chars for the encoding 15 | private static string ValidChars = "QAZ2WSX3" + "EDC4RFV5" + "TGB6YHN7" + "UJM8K9LP"; 16 | 17 | /// 18 | /// Converts an array of bytes to a Base32-k string. 19 | /// TODO: reference source give credit 20 | /// 21 | public static string ToBase32String(byte[] bytes) 22 | { 23 | StringBuilder sb = new StringBuilder(); // holds the base32 chars 24 | byte index; 25 | int hi = 5; 26 | int currentByte = 0; 27 | 28 | while (currentByte < bytes.Length) 29 | { 30 | // do we need to use the next byte? 31 | if (hi > 8) 32 | { 33 | // get the last piece from the current byte, shift it to the right 34 | // and increment the byte counter 35 | index = (byte)(bytes[currentByte++] >> (hi - 5)); 36 | if (currentByte != bytes.Length) 37 | { 38 | // if we are not at the end, get the first piece from 39 | // the next byte, clear it and shift it to the left 40 | index = (byte)(((byte)(bytes[currentByte] << (16 - hi)) >> 3) | index); 41 | } 42 | 43 | hi -= 3; 44 | } 45 | else if (hi == 8) 46 | { 47 | index = (byte)(bytes[currentByte++] >> 3); 48 | hi -= 3; 49 | } 50 | else 51 | { 52 | 53 | // simply get the stuff from the current byte 54 | index = (byte)((byte)(bytes[currentByte] << (8 - hi)) >> 3); 55 | hi += 5; 56 | } 57 | 58 | sb.Append(ValidChars[index]); 59 | } 60 | 61 | return sb.ToString(); 62 | } 63 | 64 | 65 | /// 66 | /// Converts a Base32-k string into an array of bytes. 67 | /// 68 | /// 69 | /// Input string s contains invalid Base32-k characters. 70 | /// 71 | public static byte[] FromBase32String(string str) 72 | { 73 | int numBytes = str.Length * 5 / 8; 74 | byte[] bytes = new Byte[numBytes]; 75 | 76 | // all UPPERCASE chars 77 | str = str.ToUpper(); 78 | 79 | int bit_buffer; 80 | int currentCharIndex; 81 | int bits_in_buffer; 82 | 83 | if (str.Length < 3) 84 | { 85 | bytes[0] = (byte)(ValidChars.IndexOf(str[0]) | ValidChars.IndexOf(str[1]) << 5); 86 | return bytes; 87 | } 88 | 89 | bit_buffer = (ValidChars.IndexOf(str[0]) | ValidChars.IndexOf(str[1]) << 5); 90 | bits_in_buffer = 10; 91 | currentCharIndex = 2; 92 | for (int i = 0; i < bytes.Length; i++) 93 | { 94 | bytes[i] = (byte)bit_buffer; 95 | bit_buffer >>= 8; 96 | bits_in_buffer -= 8; 97 | while (bits_in_buffer < 8 && currentCharIndex < str.Length) 98 | { 99 | bit_buffer |= ValidChars.IndexOf(str[currentCharIndex++]) << bits_in_buffer; 100 | bits_in_buffer += 5; 101 | } 102 | } 103 | 104 | return bytes; 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /GM.Api/Tokens/JwtTool.cs: -------------------------------------------------------------------------------- 1 | using JWT; 2 | using JWT.Algorithms; 3 | using Newtonsoft.Json; 4 | using Newtonsoft.Json.Linq; 5 | using System; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | 9 | namespace GM.Api.Tokens 10 | { 11 | public class JwtTool 12 | { 13 | public IJwtEncoder Encoder { get; private set; } 14 | 15 | public IJwtDecoder Decoder { get; private set; } 16 | 17 | byte[] _key; 18 | 19 | public JwtTool(string key) 20 | { 21 | _key = Encoding.ASCII.GetBytes(key); 22 | 23 | IJwtAlgorithm algorithm = new HMACSHA256Algorithm(); 24 | IJsonSerializer serializer = new SortedJsonSerializer(); 25 | IBase64UrlEncoder urlEncoder = new JwtBase64UrlEncoder(); 26 | Encoder = new JwtEncoder(algorithm, serializer, urlEncoder); 27 | 28 | IDateTimeProvider dateTimeProvider = new UtcDateTimeProvider(); 29 | IJwtValidator validator = new JwtValidator(serializer, dateTimeProvider); 30 | Decoder = new JwtDecoder(serializer, validator, urlEncoder); 31 | 32 | } 33 | 34 | 35 | public string EncodeToken(object claim) 36 | { 37 | return Encoder.Encode(claim, _key); 38 | } 39 | 40 | 41 | public string DecodeToken(string token) 42 | { 43 | return Decoder.Decode(token); 44 | } 45 | 46 | public T DecodeTokenToObject(string token) 47 | { 48 | return Decoder.DecodeToObject(token); 49 | } 50 | } 51 | 52 | 53 | 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /GM.Api/Tokens/LoginData.cs: -------------------------------------------------------------------------------- 1 | using Newtonsoft.Json; 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Text; 5 | 6 | namespace GM.Api.Tokens 7 | { 8 | /// 9 | /// Data contained within the login response JWT or as updated when refreshed 10 | /// 11 | public class LoginData 12 | { 13 | /// 14 | /// Access token used as bearer token 15 | /// 16 | [JsonProperty("access_token")] 17 | public string AccessToken { get; set; } 18 | 19 | /// 20 | /// Bearer 21 | /// 22 | [JsonProperty("token_type")] 23 | public string TokenType { get; set; } 24 | 25 | /// 26 | /// Token expiration in seconds 27 | /// (Note: I have seen the tokens expire quicker) 28 | /// 29 | [JsonProperty("expires_in")] 30 | public int ExpiresIn { get; set; } 31 | 32 | /// 33 | /// List of scopes 34 | /// 35 | [JsonProperty("scope")] 36 | public string Scope { get; set; } 37 | 38 | /// 39 | /// Information about the OnStar account 40 | /// 41 | [JsonProperty("onstar_account_info")] 42 | public Onstar_Account_Info OnStarAccountInfo { get; set; } 43 | 44 | /// 45 | /// Information about the user 46 | /// 47 | [JsonProperty("user_info")] 48 | public User_Info UserInfo { get; set; } 49 | 50 | /// 51 | /// RSA hashed itentity token (JWT) used in refresh assertion 52 | /// 53 | [JsonProperty("id_token")] 54 | public string IdToken { get; set; } 55 | 56 | /// 57 | /// Timestamp the token was recieved 58 | /// 59 | [JsonIgnore] 60 | public DateTime IssuedAtUtc { get; set; } = DateTime.UtcNow; 61 | 62 | /// 63 | /// Approximate timestamp the token expires 64 | /// 65 | [JsonIgnore] 66 | public DateTime ExpiresAtUtc => (IssuedAtUtc + TimeSpan.FromSeconds(ExpiresIn - 2)); 67 | 68 | /// 69 | /// Check if the token is expired based on timestamp 70 | /// 71 | [JsonIgnore] 72 | public bool IsExpired => (DateTime.UtcNow >= ExpiresAtUtc); 73 | 74 | 75 | } 76 | 77 | public class Onstar_Account_Info 78 | { 79 | [JsonProperty("country_code")] 80 | public string CountryCode { get; set; } 81 | 82 | [JsonProperty("account_no")] 83 | public string AccountNo { get; set; } 84 | } 85 | 86 | public class User_Info 87 | { 88 | [JsonProperty("RemoteUserId")] 89 | public string RemoteUserId { get; set; } 90 | 91 | [JsonProperty("country")] 92 | public string Country { get; set; } 93 | } 94 | 95 | } 96 | -------------------------------------------------------------------------------- /GM.Api/Tokens/LoginRequest.cs: -------------------------------------------------------------------------------- 1 | using JWT; 2 | using Newtonsoft.Json; 3 | using Newtonsoft.Json.Linq; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | namespace GM.Api.Tokens 10 | { 11 | 12 | /// 13 | /// Body that is encoded into the login and upgrade JWT 14 | /// 15 | public class LoginRequest 16 | { 17 | /// 18 | /// Client ID from configuration 19 | /// 20 | [JsonProperty("client_id", DefaultValueHandling = DefaultValueHandling.Ignore)] 21 | public string ClientId { get; set; } 22 | 23 | /// 24 | /// A GUID represented as a string, specific to the device 25 | /// (randomly generated once and saved) 26 | /// 27 | [JsonProperty("device_id", DefaultValueHandling = DefaultValueHandling.Ignore)] 28 | public string DeviceId { get; set; } 29 | 30 | /// 31 | /// OAuth grant type 32 | /// 33 | [JsonProperty("grant_type", DefaultValueHandling = DefaultValueHandling.Ignore)] 34 | public string GrantType { get; set; } 35 | 36 | /// 37 | /// Random string generated by a specifi method 38 | /// 39 | [JsonProperty("nonce", DefaultValueHandling = DefaultValueHandling.Ignore)] 40 | public string Nonce { get; set; } 41 | 42 | /// 43 | /// User's password 44 | /// 45 | [JsonProperty("password", DefaultValueHandling = DefaultValueHandling.Ignore)] 46 | public string Password { get; set; } 47 | 48 | /// 49 | /// Scope 50 | /// ex: onstar gmoc commerce user_trailer msso 51 | /// 52 | [JsonProperty("scope", DefaultValueHandling = DefaultValueHandling.Ignore)] 53 | public string Scope { get; set; } 54 | 55 | /// 56 | /// Current timestamp in UTC using "yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffK" format string 57 | /// 58 | [JsonProperty("timestamp", DefaultValueHandling = DefaultValueHandling.Ignore)] 59 | public string Timestamp { get; set; } 60 | 61 | /// 62 | /// Username for GM account 63 | /// 64 | [JsonProperty("username", DefaultValueHandling = DefaultValueHandling.Ignore)] 65 | public string Username { get; set; } 66 | 67 | 68 | /// 69 | /// OnStar PIN used to upgrade token 70 | /// 71 | [JsonProperty("credential", DefaultValueHandling = DefaultValueHandling.Ignore)] 72 | public string Credential { get; set; } 73 | 74 | /// 75 | /// "PIN" for onstar pin 76 | /// 77 | [JsonProperty("credential_type", DefaultValueHandling = DefaultValueHandling.Ignore)] 78 | public string CredentialType { get; set; } 79 | 80 | /// 81 | /// IdToken from login payload - used for refreshing 82 | /// 83 | [JsonProperty("assertion", DefaultValueHandling = DefaultValueHandling.Ignore)] 84 | public string Assertion { get; set; } 85 | 86 | 87 | } 88 | 89 | 90 | 91 | 92 | 93 | } 94 | -------------------------------------------------------------------------------- /GM.Api/Tokens/SortedJsonSerializer.cs: -------------------------------------------------------------------------------- 1 | using JWT; 2 | using Newtonsoft.Json; 3 | using Newtonsoft.Json.Linq; 4 | using System; 5 | using System.Collections.Generic; 6 | using System.Linq; 7 | using System.Text; 8 | 9 | namespace GM.Api.Tokens 10 | { 11 | /// 12 | /// Custom JSON serialized used with JWT.net 13 | /// JWT.net's JWT header is not alphebetized by default... 14 | /// 15 | public class SortedJsonSerializer : IJsonSerializer 16 | { 17 | public string Serialize(object obj) 18 | { 19 | return NormalizeJsonString(Newtonsoft.Json.JsonConvert.SerializeObject(obj)); 20 | } 21 | 22 | public T Deserialize(string json) 23 | { 24 | return JsonConvert.DeserializeObject(json); 25 | } 26 | 27 | 28 | public static string NormalizeJsonString(string json) 29 | { 30 | // Parse json string into JObject. 31 | var parsedObject = JObject.Parse(json); 32 | 33 | // Sort properties of JObject. 34 | var normalizedObject = SortPropertiesAlphabetically(parsedObject); 35 | 36 | // Serialize JObject . 37 | return JsonConvert.SerializeObject(normalizedObject); 38 | } 39 | 40 | private static JObject SortPropertiesAlphabetically(JObject original) 41 | { 42 | var result = new JObject(); 43 | 44 | foreach (var property in original.Properties().ToList().OrderBy(p => p.Name)) 45 | { 46 | var value = property.Value as JObject; 47 | 48 | if (value != null) 49 | { 50 | value = SortPropertiesAlphabetically(value); 51 | result.Add(property.Name, value); 52 | } 53 | else 54 | { 55 | result.Add(property.Name, property.Value); 56 | } 57 | } 58 | 59 | return result; 60 | } 61 | 62 | 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /GM.Api/helpers.cs: -------------------------------------------------------------------------------- 1 | using JWT; 2 | using JWT.Algorithms; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Net.Http.Headers; 6 | using System.Security.Cryptography; 7 | using System.Text; 8 | 9 | namespace GM.Api 10 | { 11 | static class helpers 12 | { 13 | public static string GenerateNonce() 14 | { 15 | //17.25 bytes = 130 bits 16 | //return new BigInteger(130, new SecureRandom()).toString(32); 17 | 18 | RNGCryptoServiceProvider provider = new RNGCryptoServiceProvider(); 19 | var byteArray = new byte[17]; 20 | 21 | provider.GetBytes(byteArray); 22 | var nonce = Tokens.Base32.ToBase32String(byteArray); 23 | return nonce.ToLower().Substring(0, 26); 24 | } 25 | 26 | /// 27 | /// Set an HTTP header to a single value, clearing any existing values 28 | /// 29 | /// 30 | /// 31 | /// 32 | public static void SetValue(this HttpHeaderValueCollection headerValue, string value) where T: class 33 | { 34 | headerValue.Clear(); 35 | headerValue.ParseAdd(value); 36 | } 37 | 38 | 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /GM.WindowsUI/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 |
6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | https://gmsigner.herokuapp.com/ 45 | 46 | 47 | 48 | -------------------------------------------------------------------------------- /GM.WindowsUI/App.xaml: -------------------------------------------------------------------------------- 1 |  6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /GM.WindowsUI/App.xaml.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Configuration; 4 | using System.Data; 5 | using System.Linq; 6 | using System.Threading.Tasks; 7 | using System.Windows; 8 | 9 | namespace GM.WindowsUI 10 | { 11 | /// 12 | /// Interaction logic for App.xaml 13 | /// 14 | public partial class App : Application 15 | { 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /GM.WindowsUI/BrandWindow.xaml: -------------------------------------------------------------------------------- 1 |  9 | 10 | 11 |