Skip to content

Commit a2230ff

Browse files
committed
Initial "KnownApplication" sign-in.
1 parent 406931d commit a2230ff

92 files changed

Lines changed: 720 additions & 422 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Shuttle.Access.Application/ActivateIdentityParticipant.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public async Task ProcessMessageAsync(IParticipantContext<RequestResponseMessage
2727
var message = context.Message.Request;
2828
var now = DateTime.UtcNow;
2929

30-
var specification = new DataAccess.Query.Identity.Specification();
30+
var specification = new DataAccess.Identity.Specification();
3131

3232
if (message.Id.HasValue)
3333
{

Shuttle.Access.Application/ConfigureApplicationParticipant.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task ProcessMessageAsync(IParticipantContext<ConfigureApplication>
4949
{
5050
Guard.AgainstNull(context);
5151

52-
var roleSpecification = new DataAccess.Query.Role.Specification().AddName("Administrator");
52+
var roleSpecification = new DataAccess.Role.Specification().AddName("Administrator");
5353

5454
var administratorExists = await _roleQuery.CountAsync(roleSpecification) > 0;
5555

@@ -81,7 +81,7 @@ public async Task ProcessMessageAsync(IParticipantContext<ConfigureApplication>
8181

8282
foreach (var permission in _permissions)
8383
{
84-
if (await _permissionQuery.ContainsAsync(new DataAccess.Query.Permission.Specification().AddName(permission)))
84+
if (await _permissionQuery.ContainsAsync(new DataAccess.Permission.Specification().AddName(permission)))
8585
{
8686
continue;
8787
}

Shuttle.Access.Application/GetPasswordResetTokenParticipant.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public GetPasswordResetTokenParticipant(IIdentityQuery identityQuery, IEventStor
2323
public async Task ProcessMessageAsync(IParticipantContext<RequestResponseMessage<GetPasswordResetToken, Guid>> context)
2424
{
2525
var identityName = context.Message.Request.Name;
26-
var query = (await _identityQuery.SearchAsync(new DataAccess.Query.Identity.Specification().WithName(identityName))).SingleOrDefault();
26+
var query = (await _identityQuery.SearchAsync(new DataAccess.Identity.Specification().WithName(identityName))).SingleOrDefault();
2727

2828
if (query == null)
2929
{

Shuttle.Access.Application/Messages/RegisterSession.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public RegisterSession(string identityName)
2020
public SessionRegistrationType RegistrationType { get; private set; } = SessionRegistrationType.None;
2121
public SessionRegistrationResult Result { get; private set; } = SessionRegistrationResult.Forbidden;
2222
public Session? Session { get; private set; }
23+
public string SessionTokenExchangeUrl { get; private set; } = string.Empty;
24+
public bool HasKnownApplicationOptions => KnownApplicationOptions != null;
2325

2426
public RegisterSession DelegationSessionInvalid()
2527
{
@@ -114,4 +116,20 @@ public RegisterSession UseToken(Guid token)
114116

115117
return this;
116118
}
119+
120+
public RegisterSession WithKnownApplicationOptions(KnownApplicationOptions knownApplicationOptions)
121+
{
122+
KnownApplicationOptions = Guard.AgainstNull(knownApplicationOptions);
123+
124+
return this;
125+
}
126+
127+
public KnownApplicationOptions? KnownApplicationOptions { get; private set; }
128+
129+
public RegisterSession WithSessionTokenExchangeUrl(string sessionTokenExchangeUrl)
130+
{
131+
SessionTokenExchangeUrl = Guard.AgainstNullOrEmptyString(sessionTokenExchangeUrl);
132+
133+
return this;
134+
}
117135
}

Shuttle.Access.Application/RefreshSessionParticipant.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public async Task ProcessMessageAsync(IParticipantContext<RefreshSession> contex
2929
{
3030
Guard.AgainstNull(context);
3131

32-
DataAccess.Query.Session.Specification specification = new();
32+
DataAccess.Session.Specification specification = new();
3333

3434
if (context.Message.Token.HasValue)
3535
{

Shuttle.Access.Application/RegisterIdentityParticipant.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ public async Task ProcessMessageAsync(IParticipantContext<RequestResponseMessage
6363

6464
stream.Add(registered);
6565

66-
var count = await _identityQuery.CountAsync(new DataAccess.Query.Identity.Specification().WithRoleName("Administrator"));
66+
var count = await _identityQuery.CountAsync(new DataAccess.Identity.Specification().WithRoleName("Administrator"));
6767

6868
if (count == 0)
6969
{
70-
var roles = (await _roleQuery.SearchAsync(new DataAccess.Query.Role.Specification().AddName("Administrator"))).ToList();
70+
var roles = (await _roleQuery.SearchAsync(new DataAccess.Role.Specification().AddName("Administrator"))).ToList();
7171

7272
if (roles.Count != 1)
7373
{

Shuttle.Access.Application/RegisterSessionParticipant.cs

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,21 +10,23 @@ namespace Shuttle.Access.Application;
1010

1111
public class RegisterSessionParticipant : IParticipant<RegisterSession>
1212
{
13+
private readonly ISessionTokenExchangeRepository _sessionTokenExchangeRepository;
1314
private readonly AccessOptions _accessOptions;
1415
private readonly IAuthenticationService _authenticationService;
1516
private readonly IAuthorizationService _authorizationService;
1617
private readonly IIdentityQuery _identityQuery;
1718
private readonly ISessionQuery _sessionQuery;
1819
private readonly ISessionRepository _sessionRepository;
1920

20-
public RegisterSessionParticipant(IOptions<AccessOptions> accessOptions, IAuthenticationService authenticationService, IAuthorizationService authorizationService, ISessionRepository sessionRepository, ISessionQuery sessionQuery, IIdentityQuery identityQuery)
21+
public RegisterSessionParticipant(IOptions<AccessOptions> accessOptions, IAuthenticationService authenticationService, IAuthorizationService authorizationService, ISessionRepository sessionRepository, ISessionQuery sessionQuery, IIdentityQuery identityQuery, ISessionTokenExchangeRepository sessionTokenExchangeRepository)
2122
{
2223
_accessOptions = Guard.AgainstNull(accessOptions).Value;
2324
_authenticationService = Guard.AgainstNull(authenticationService);
2425
_sessionQuery = Guard.AgainstNull(sessionQuery);
2526
_authorizationService = Guard.AgainstNull(authorizationService);
2627
_sessionRepository = Guard.AgainstNull(sessionRepository);
2728
_identityQuery = Guard.AgainstNull(identityQuery);
29+
_sessionTokenExchangeRepository = Guard.AgainstNull(sessionTokenExchangeRepository);
2830
}
2931

3032
public async Task ProcessMessageAsync(IParticipantContext<RegisterSession> context)
@@ -71,14 +73,14 @@ public async Task ProcessMessageAsync(IParticipantContext<RegisterSession> conte
7173
}
7274
}
7375

74-
if ((await _identityQuery.SearchAsync(new DataAccess.Query.Identity.Specification().WithName(message.IdentityName), context.CancellationToken)).SingleOrDefault() == null)
76+
if ((await _identityQuery.SearchAsync(new DataAccess.Identity.Specification().WithName(message.IdentityName), context.CancellationToken)).SingleOrDefault() == null)
7577
{
7678
message.UnknownIdentity();
7779

7880
return;
7981
}
8082

81-
var specification = new DataAccess.Query.Session.Specification();
83+
var specification = new DataAccess.Session.Specification();
8284

8385
if (message.RegistrationType == SessionRegistrationType.Token)
8486
{
@@ -127,6 +129,8 @@ public async Task ProcessMessageAsync(IParticipantContext<RegisterSession> conte
127129
message.Registered(session);
128130
}
129131

132+
return;
133+
130134
async Task SaveAsync()
131135
{
132136
foreach (var permission in await _authorizationService.GetPermissionsAsync(message.IdentityName, context.CancellationToken))
@@ -135,6 +139,15 @@ async Task SaveAsync()
135139
}
136140

137141
await _sessionRepository.SaveAsync(session, context.CancellationToken);
142+
143+
if (message.HasKnownApplicationOptions)
144+
{
145+
var sessionTokenExchange = new SessionTokenExchange(Guid.NewGuid(), session.Token, DateTime.UtcNow.Add(_accessOptions.SessionTokenExchangeValidityTimeSpan));
146+
147+
await _sessionTokenExchangeRepository.SaveAsync(sessionTokenExchange, context.CancellationToken);
148+
149+
message.WithSessionTokenExchangeUrl($"{message.KnownApplicationOptions!.SessionTokenExchangeUrl}/{sessionTokenExchange.ExchangeToken}");
150+
}
138151
}
139152
}
140153
}

Shuttle.Access.Application/ResetPasswordParticipant.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public async Task ProcessMessageAsync(IParticipantContext<RequestMessage<ResetPa
2525
{
2626
Guard.AgainstNull(context);
2727

28-
var queryIdentity = (await _identityQuery.SearchAsync(new DataAccess.Query.Identity.Specification().WithName(context.Message.Request.Name))).SingleOrDefault();
28+
var queryIdentity = (await _identityQuery.SearchAsync(new DataAccess.Identity.Specification().WithName(context.Message.Request.Name))).SingleOrDefault();
2929

3030
if (queryIdentity == null)
3131
{

Shuttle.Access.Application/ReviewSetIdentityRoleParticipant.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public async Task ProcessMessageAsync(IParticipantContext<RequestMessage<SetIden
2323
Guard.AgainstNull(context);
2424

2525
var request = context.Message.Request;
26-
var roles = (await _roleQuery.SearchAsync(new DataAccess.Query.Role.Specification().AddName("Administrator"))).ToList();
26+
var roles = (await _roleQuery.SearchAsync(new DataAccess.Role.Specification().AddName("Administrator"))).ToList();
2727

2828
if (roles.Count != 1)
2929
{

Shuttle.Access.AspNetCore.OAuth/.package/AssemblyInfo.cs.template

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)