Skip to content

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
BrendanGrant committed Jul 5, 2018
1 parent ea45aaa commit 21c9655
Show file tree
Hide file tree
Showing 31 changed files with 809 additions and 0 deletions.
12 changes: 12 additions & 0 deletions NOnStar.ConsoleApp/NOnStar.ConsoleApp.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\NOnStar\NOnStar.csproj" />
</ItemGroup>

</Project>
22 changes: 22 additions & 0 deletions NOnStar.ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System;

namespace NOnStar.ConsoleApp
{
class Program
{
static void Main(string[] args)
{
//must specify email address, password & PIN used for OnStar
var client = new OnStarClient("your_email_address", "onstar_password", "pin");

//Uncomment and try one:
//client.UnlockVehical().GetAwaiter().GetResult();
//client.LockVehical().GetAwaiter().GetResult();
//client.StartVehical().GetAwaiter().GetResult();
//client.StopVehical().GetAwaiter().GetResult();

Console.WriteLine("Done");
Console.ReadLine();
}
}
}
31 changes: 31 additions & 0 deletions NOnStar.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2035
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NOnStar", "NOnStar\NOnStar.csproj", "{B2E505EC-2F16-4DF1-9AA9-80176658D455}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NOnStar.ConsoleApp", "NOnStar.ConsoleApp\NOnStar.ConsoleApp.csproj", "{F9E9AE6A-1D1F-4D25-8ECF-41A16E17707D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B2E505EC-2F16-4DF1-9AA9-80176658D455}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B2E505EC-2F16-4DF1-9AA9-80176658D455}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B2E505EC-2F16-4DF1-9AA9-80176658D455}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B2E505EC-2F16-4DF1-9AA9-80176658D455}.Release|Any CPU.Build.0 = Release|Any CPU
{F9E9AE6A-1D1F-4D25-8ECF-41A16E17707D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F9E9AE6A-1D1F-4D25-8ECF-41A16E17707D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F9E9AE6A-1D1F-4D25-8ECF-41A16E17707D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F9E9AE6A-1D1F-4D25-8ECF-41A16E17707D}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {A727B3BB-C9A5-4273-A4B8-705522DE1F87}
EndGlobalSection
EndGlobal
42 changes: 42 additions & 0 deletions NOnStar/Auth.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NOnStar
{
abstract class BaseAuth
{
public string nonce = GetNonce();
public string timestamp = GetTimestamp();

protected static string GetNonce()
{
return Guid.NewGuid().ToString("N").ToLower();
}

protected static string GetTimestamp()
{
return DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
}
}

class DeviceAuth : BaseAuth
{
public string client_id;
public string device_id;
public string grant_type;
public string username;
public string password;
public string scope = "onstar gmoc commerce msso";
}


class PinAuth : BaseAuth
{
public string credential;
public string device_id;
public string scope = "onstar commerce";
public string credential_type = "PIN";
public string client_id;
}
}
11 changes: 11 additions & 0 deletions NOnStar/CommandAndControl/Body.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NOnStar.CommandAndControl
{
class Body
{
public Error error { get; set; }
}
}
37 changes: 37 additions & 0 deletions NOnStar/CommandAndControl/CommandRequestStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NOnStar.CommandAndControl
{
public class CommandRequestStatus
{
public bool Successful { get; internal set; }
public string ErrorMessage { get; internal set; }

public static CommandRequestStatus GetSuccessful()
{
return new CommandRequestStatus() { Successful = true };
}

public static CommandRequestStatus GetFailed(string errorMessage)
{
return new CommandRequestStatus() { Successful = false, ErrorMessage = errorMessage };
}
}

public class CommandRequestStatus<T> : CommandRequestStatus
{
public T Content { get; internal set; }

public static CommandRequestStatus<T> GetSuccessful(T content)
{
return new CommandRequestStatus<T>() { Successful = true, Content = content };
}

public static new CommandRequestStatus<T> GetFailed(string errorMessage)
{
return new CommandRequestStatus<T>() { Successful = false, ErrorMessage = errorMessage };
}
}
}
16 changes: 16 additions & 0 deletions NOnStar/CommandAndControl/CommandResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NOnStar.CommandAndControl
{
class CommandResponse
{
public DateTime requestTime { get; set; }
public DateTime completionTime { get; set; }
public string url { get; set; }
public string status { get; set; }
public string type { get; set; }
public Body body { get; set; }
}
}
14 changes: 14 additions & 0 deletions NOnStar/CommandAndControl/Error.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NOnStar.CommandAndControl
{
class Error
{
public string code { get; set; }
public string description { get; set; }
public string subCode { get; set; }
public string subCodeDescription { get; set; }
}
}
11 changes: 11 additions & 0 deletions NOnStar/CommandAndControl/OuterCommandResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace NOnStar.CommandAndControl
{
class OuterCommandResponse
{
public CommandResponse commandResponse { get; set; }
}
}
35 changes: 35 additions & 0 deletions NOnStar/ExtensionMethods.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using JWT.Builder;
using System;
using System.Collections.Generic;
using System.Text;

namespace NOnStar
{
static class ExtensionMethods
{
public static JwtBuilder AddClaims(this JwtBuilder builder, DeviceAuth deviceAuth)
{
return builder
.AddClaim("client_id", deviceAuth.client_id)
.AddClaim("device_id", deviceAuth.device_id)
.AddClaim("username", deviceAuth.username)
.AddClaim("password", deviceAuth.password)
.AddClaim("nonce", deviceAuth.nonce)
.AddClaim("timestamp", deviceAuth.timestamp)
.AddClaim("scope", deviceAuth.scope)
.AddClaim("grant_type", deviceAuth.grant_type);
}

public static JwtBuilder AddClaims(this JwtBuilder builder, PinAuth pinPayload)
{
return builder
.AddClaim("client_id", pinPayload.client_id)
.AddClaim("device_id", pinPayload.device_id)
.AddClaim("credential", pinPayload.credential)
.AddClaim("credential_type", pinPayload.credential_type)
.AddClaim("nonce", pinPayload.nonce)
.AddClaim("timestamp", pinPayload.timestamp)
.AddClaim("scope", pinPayload.scope);
}
}
}
12 changes: 12 additions & 0 deletions NOnStar/NOnStar.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<AssemblyName>NOnStar</AssemblyName>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="JWT" Version="4.0.0" />
</ItemGroup>

</Project>
Loading

0 comments on commit 21c9655

Please sign in to comment.