-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from bunq/release/0.12.0
Merge branch 'release/0.12.0'
- Loading branch information
Showing
6 changed files
with
302 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using Bunq.Sdk.Context; | ||
using Bunq.Sdk.Exception; | ||
using Bunq.Sdk.Json; | ||
using Bunq.Sdk.Model.Core; | ||
using Bunq.Sdk.Model.Generated.Endpoint; | ||
using Mono.Options; | ||
using Tinker.Utils; | ||
|
||
namespace TinkerSrc | ||
{ | ||
public class CreateOauthClient : ITinker | ||
{ | ||
/// <summary> | ||
/// API constants. | ||
/// </summary> | ||
protected const string OPTION_CONTEXT = "context="; | ||
protected const string OPTION_REDIRECT_URI = "redirect="; | ||
|
||
/** | ||
* File constants. | ||
*/ | ||
protected const string FILE_OAUTH_CONFIGURATION = "oauth.conf"; | ||
|
||
/** | ||
* Error constants. | ||
*/ | ||
protected const string ERROR_MISSING_MANDATORY_OPTION = "Missing mandatory option."; | ||
|
||
public void Run(string[] args) | ||
{ | ||
Dictionary<string, string> allOption = AssertMandatoryOptions(args); | ||
|
||
BunqContext.LoadApiContext( | ||
ApiContext.Restore(allOption[OPTION_CONTEXT]) | ||
); | ||
|
||
OauthClient oauthClient; | ||
if (File.Exists(FILE_OAUTH_CONFIGURATION)) | ||
{ | ||
oauthClient = OauthClient.CreateFromJsonString(File.ReadAllText(FILE_OAUTH_CONFIGURATION)); | ||
} | ||
else | ||
{ | ||
int oauthClientId = OauthClient.Create().Value; | ||
|
||
OauthCallbackUrl.Create(oauthClientId, allOption[OPTION_REDIRECT_URI]); | ||
oauthClient = OauthClient.Get(oauthClientId).Value; | ||
|
||
String serializedClient = BunqJsonConvert.SerializeObject(oauthClient); | ||
File.WriteAllText(FILE_OAUTH_CONFIGURATION, serializedClient); | ||
} | ||
|
||
OauthAuthorizationUri authorizationUri = OauthAuthorizationUri.Create( | ||
OauthResponseType.CODE, | ||
allOption[OPTION_REDIRECT_URI], | ||
oauthClient | ||
); | ||
|
||
Console.WriteLine(" | Created oauth client. Stored in {0}.", FILE_OAUTH_CONFIGURATION); | ||
Console.WriteLine(" | Point your user to {0} to obtain an Authorization code.", authorizationUri.AuthorizationUri); | ||
} | ||
|
||
private Dictionary<string, string> AssertMandatoryOptions(string[] allArgument) | ||
{ | ||
Dictionary<string, string> allOption = new Dictionary<string, string>(); | ||
|
||
new OptionSet | ||
{ | ||
{OPTION_CONTEXT, value => allOption.Add(OPTION_CONTEXT, value)}, | ||
{OPTION_REDIRECT_URI, value => allOption.Add(OPTION_REDIRECT_URI, value)} | ||
}.Parse(allArgument); | ||
|
||
if (allOption[OPTION_CONTEXT] != null && | ||
allOption[OPTION_REDIRECT_URI] != null) { | ||
return allOption; | ||
} | ||
|
||
throw new BunqException(ERROR_MISSING_MANDATORY_OPTION); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Security.Cryptography.X509Certificates; | ||
using Bunq.Sdk.Context; | ||
using Bunq.Sdk.Exception; | ||
using Bunq.Sdk.Model.Generated.Object; | ||
using Bunq.Sdk.Security; | ||
using Mono.Options; | ||
using Tinker.Utils; | ||
using TinkerSrc.Lib; | ||
|
||
namespace TinkerSrc | ||
{ | ||
public class CreatePsd2Configuration : ITinker | ||
{ | ||
/// <summary> | ||
/// API constants. | ||
/// </summary> | ||
protected const string API_DEVICE_DESCRIPTION = "##### YOUR DEVICE DESCRIPTION #####"; | ||
|
||
/// <summary> | ||
/// Option constants. | ||
/// </summary> | ||
protected const string OPTION_CREDENTIALS = "credentials="; | ||
protected const string OPTION_CERTIFICATE_CHAIN = "chain="; | ||
protected const string OPTION_PASSPHRASE = "pass="; | ||
|
||
/// <summary> | ||
/// Error constants. | ||
/// </summary> | ||
protected const string ERROR_MISSING_MANDATORY_OPTION = "Missing mandatory option."; | ||
|
||
/// <summary> | ||
/// File constants. | ||
/// </summary> | ||
protected const string FILE_CONTEXT = "bunq-psd2.conf"; | ||
|
||
public void Run(string[] args) | ||
{ | ||
Dictionary<string, string> allOption = AssertMandatoryOptions(args); | ||
|
||
ApiContext apiContext = ApiContext.CreateForPsd2( | ||
ShareLib.DetermineEnvironmentType(args), | ||
SecurityUtils.GetCertificateFromFile(allOption[OPTION_CREDENTIALS], allOption[OPTION_PASSPHRASE]), | ||
new X509CertificateCollection () { | ||
SecurityUtils.GetCertificateFromFile(allOption[OPTION_CERTIFICATE_CHAIN]) | ||
}, | ||
API_DEVICE_DESCRIPTION, | ||
new List<string>() | ||
); | ||
|
||
apiContext.Save(FILE_CONTEXT); | ||
} | ||
|
||
private Dictionary<string, string> AssertMandatoryOptions(string[] allArgument) | ||
{ | ||
Dictionary<string, string> allOption = new Dictionary<string, string>(); | ||
|
||
new OptionSet | ||
{ | ||
{OPTION_CREDENTIALS, value => allOption.Add(OPTION_CREDENTIALS, value)}, | ||
{OPTION_CERTIFICATE_CHAIN, value => allOption.Add(OPTION_CERTIFICATE_CHAIN, value)}, | ||
{OPTION_PASSPHRASE, value => allOption.Add(OPTION_PASSPHRASE, value)} | ||
}.Parse(allArgument); | ||
|
||
if (allOption[OPTION_CERTIFICATE_CHAIN] != null && | ||
allOption[OPTION_CREDENTIALS] != null && | ||
allOption[OPTION_PASSPHRASE] != null) { | ||
return allOption; | ||
} | ||
|
||
throw new BunqException(ERROR_MISSING_MANDATORY_OPTION); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Threading.Tasks; | ||
using Bunq.Sdk.Context; | ||
using Bunq.Sdk.Exception; | ||
using Bunq.Sdk.Model.Core; | ||
using Bunq.Sdk.Model.Generated.Endpoint; | ||
using Mono.Options; | ||
using Tinker.Utils; | ||
using TinkerSrc.Lib; | ||
|
||
namespace TinkerSrc | ||
{ | ||
public class TestOauth : ITinker | ||
{ | ||
/// <summary> | ||
/// Option constants. | ||
/// </summary> | ||
protected const string OPTION_AUTH_CODE = "code="; | ||
protected const string OPTION_CLIENT_CONFIGURATION = "configuration="; | ||
protected const string OPTION_REDIRECT = "redirect="; | ||
protected const string OPTION_CONTEXT = "context="; | ||
|
||
/// <summary> | ||
/// API constants. | ||
/// </summary> | ||
protected const string API_DEVICE_DESCRIPTION = "##### YOUR DEVICE DESCRIPTION #####"; | ||
|
||
/// <summary> | ||
/// Error constants. | ||
/// </summary> | ||
protected const string ERROR_MISSING_MANDATORY_OPTION = "Missing mandatory option."; | ||
|
||
public void Run(string[] args) | ||
{ | ||
Dictionary<string, string> allOption = AssertMandatoryOptions(args); | ||
|
||
ApiContext apiContext = ApiContext.Restore(allOption[OPTION_CONTEXT]); | ||
BunqContext.LoadApiContext(apiContext); | ||
|
||
OauthAccessToken accessToken = OauthAccessToken.Create( | ||
OauthGrantType.AUTHORIZATION_CODE, | ||
allOption[OPTION_AUTH_CODE], | ||
allOption[OPTION_REDIRECT], | ||
CreateOauthClientFromFile(allOption[OPTION_CLIENT_CONFIGURATION]) | ||
); | ||
|
||
apiContext = CreateApiContextByOauthToken( | ||
accessToken, | ||
ShareLib.DetermineEnvironmentType(args) | ||
); | ||
BunqContext.LoadApiContext(apiContext); | ||
|
||
(new UserOverview()).Run(new String[]{}); | ||
} | ||
|
||
|
||
private Dictionary<string, string> AssertMandatoryOptions(string[] allArgument) | ||
{ | ||
Dictionary<string, string> allOption = new Dictionary<string, string>(); | ||
|
||
new OptionSet | ||
{ | ||
{OPTION_AUTH_CODE, value => allOption.Add(OPTION_AUTH_CODE, value)}, | ||
{OPTION_REDIRECT, value => allOption.Add(OPTION_REDIRECT, value)}, | ||
{OPTION_CONTEXT, value => allOption.Add(OPTION_CONTEXT, value)}, | ||
{OPTION_CLIENT_CONFIGURATION, value => allOption.Add(OPTION_CLIENT_CONFIGURATION, value)} | ||
}.Parse(allArgument); | ||
|
||
if (allOption[OPTION_AUTH_CODE] != null && | ||
allOption[OPTION_REDIRECT] != null && | ||
allOption[OPTION_CONTEXT] != null && | ||
allOption[OPTION_CLIENT_CONFIGURATION] != null) { | ||
return allOption; | ||
} | ||
|
||
throw new BunqException(ERROR_MISSING_MANDATORY_OPTION); | ||
} | ||
|
||
private OauthClient CreateOauthClientFromFile(String path) | ||
{ | ||
return OauthClient.CreateFromJsonString( | ||
File.ReadAllText(path) | ||
); | ||
} | ||
|
||
private static ApiContext CreateApiContextByOauthToken(OauthAccessToken token, ApiEnvironmentType environmentType) | ||
{ | ||
return ApiContext.Create( | ||
environmentType, | ||
token.Token, | ||
API_DEVICE_DESCRIPTION | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>netcoreapp1.1</TargetFramework> | ||
<TargetFramework>netcoreapp2.2</TargetFramework> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="Bunq.Sdk" Version="1.1.0" /> | ||
<PackageReference Include="Bunq.Sdk" Version="1.12.1" /> | ||
<PackageReference Include="Mono.Options" Version="5.3.0.1" /> | ||
</ItemGroup> | ||
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters