Skip to content

Commit e0879ec

Browse files
committed
Added grant data.
1 parent 949d6e6 commit e0879ec

File tree

7 files changed

+38
-9
lines changed

7 files changed

+38
-9
lines changed

Shuttle.OAuth/.package/package.nuspec

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<repository type="git" url="https://github.com/Shuttle/Shuttle.OAuth.git" />
1414
<projectUrl>https://github.com/Shuttle/Shuttle.OAuth</projectUrl>
1515
<description>OAuth infrastructure components.</description>
16-
<copyright>Copyright (c) 2024, Eben Roux</copyright>
16+
<copyright>Copyright (c) 2025, Eben Roux</copyright>
1717
<tags>oauth</tags>
1818
<dependencies>
1919
<dependency id="Microsoft.Extensions.DependencyInjection" version="8.0.1" />

Shuttle.OAuth/IOAuthService.cs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
using System.Threading.Tasks;
1+
using System.Collections.Generic;
2+
using System.Threading.Tasks;
23

34
namespace Shuttle.OAuth;
45

56
public interface IOAuthService
67
{
78
Task<dynamic> GetDataAsync(OAuthGrant grant, string code);
8-
Task<OAuthGrant> RegisterAsync(string providerName);
9+
Task<OAuthGrant> RegisterAsync(string providerName, IDictionary<string, string>? data = null);
910
}

Shuttle.OAuth/OAuthGrant.cs

+19-1
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
11
using System;
2+
using System.Collections.Generic;
23
using Shuttle.Core.Contract;
34

45
namespace Shuttle.OAuth;
56

67
public class OAuthGrant
78
{
8-
public OAuthGrant(Guid id, string providerName)
9+
public OAuthGrant(Guid id, string providerName, IDictionary<string, string>? data = null)
910
{
1011
Id = id;
12+
Data = data ?? new Dictionary<string, string>();
1113
ProviderName = Guard.AgainstNullOrEmptyString(providerName);
1214
}
1315

1416
public string CodeChallenge { get; private set; } = default!;
1517
public string CodeVerifier { get; private set; } = default!;
1618

1719
public Guid Id { get; }
20+
public IDictionary<string, string> Data { get; }
1821
public string ProviderName { get; }
1922

2023
public OAuthGrant WithCodeChallenge(string codeChallenge, string codeVerifier)
@@ -24,4 +27,19 @@ public OAuthGrant WithCodeChallenge(string codeChallenge, string codeVerifier)
2427

2528
return this;
2629
}
30+
31+
public bool HasData(string name)
32+
{
33+
return Data.ContainsKey(Guard.AgainstNullOrEmptyString(name));
34+
}
35+
36+
public string GetData(string name)
37+
{
38+
if (!HasData(name))
39+
{
40+
throw new InvalidOperationException(string.Format(Resources.OAuthGrantDataNameNotFoundException, name));
41+
}
42+
43+
return Data[Guard.AgainstNullOrEmptyString(name)];
44+
}
2745
}

Shuttle.OAuth/OAuthService.cs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.Dynamic;
43
using System.Linq;
54
using System.Text;
65
using System.Threading.Tasks;
7-
using System.Web;
86
using Microsoft.Extensions.Options;
97
using RestSharp;
108
using Shuttle.Core.Contract;
@@ -25,11 +23,11 @@ public OAuthService(IOptions<OAuthOptions> oauthOptions, IOAuthGrantRepository o
2523
_oauthGrantRepository = Guard.AgainstNull(oauthGrantRepository);
2624
}
2725

28-
public async Task<OAuthGrant> RegisterAsync(string providerName)
26+
public async Task<OAuthGrant> RegisterAsync(string providerName, IDictionary<string, string>? data = null)
2927
{
3028
var oauthProviderOptions = _oauthOptions.GetProviderOptions(providerName);
3129

32-
var grant = new OAuthGrant(Guid.NewGuid(), providerName);
30+
var grant = new OAuthGrant(Guid.NewGuid(), providerName, data);
3331

3432
if (!string.IsNullOrWhiteSpace(oauthProviderOptions.Authorize.CodeChallengeMethod))
3533
{

Shuttle.OAuth/Properties/AssemblyInfo.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
[assembly: AssemblyTitle(".NET Unified Platform")]
55
[assembly: AssemblyVersion("20.0.0.0")]
6-
[assembly: AssemblyCopyright("Copyright (c) 2024, Eben Roux")]
6+
[assembly: AssemblyCopyright("Copyright (c) 2025, Eben Roux")]
77
[assembly: AssemblyProduct("Shuttle.OAuth")]
88
[assembly: AssemblyCompany("Eben Roux")]
99
[assembly: AssemblyConfiguration("Release")]

Shuttle.OAuth/Resources.Designer.cs

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Shuttle.OAuth/Resources.resx

+3
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,7 @@
164164
<value>Could not find an OAuthProviderOptions instance with name '{0}'.</value>
165165
<comment>0 = provider name</comment>
166166
</data>
167+
<data name="OAuthGrantDataNameNotFoundException" xml:space="preserve">
168+
<value>Could not find a data item with name '{0}'.</value>
169+
</data>
167170
</root>

0 commit comments

Comments
 (0)