mirror of
https://github.com/bitwarden/mobile
synced 2026-01-06 10:34:07 +00:00
[SSO] Auto enroll during set password (#1520)
* [SSO] Auto enroll during set password * Updated with requested changes
This commit is contained in:
@@ -177,7 +177,7 @@ namespace Bit.Core.Services
|
||||
return SendAsync<PasswordVerificationRequest, object>(HttpMethod.Post, "/accounts/verify-password", request,
|
||||
true, false);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
#region Folder APIs
|
||||
@@ -402,6 +402,26 @@ namespace Bit.Core.Services
|
||||
string.Concat("/hibp/breach?username=", username), null, true, true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Organizations APIs
|
||||
|
||||
public Task<OrganizationKeysResponse> GetOrganizationKeysAsync(string id)
|
||||
{
|
||||
return SendAsync<object, OrganizationKeysResponse>(HttpMethod.Get, $"/organizations/{id}/keys", null, true, true);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Organization User APIs
|
||||
|
||||
public Task PutOrganizationUserResetPasswordEnrollmentAsync(string orgId, string userId,
|
||||
OrganizationUserResetPasswordEnrollmentRequest request)
|
||||
{
|
||||
return SendAsync<OrganizationUserResetPasswordEnrollmentRequest, object>(HttpMethod.Put,
|
||||
$"/organizations/{orgId}/users/{userId}/reset-password-enrollment", request, true, false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Helpers
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Threading.Tasks;
|
||||
@@ -180,6 +181,23 @@ namespace Bit.Core.Services
|
||||
return true;
|
||||
}
|
||||
|
||||
public Tuple<ResetPasswordPolicyOptions, bool> GetResetPasswordPolicyOptions(IEnumerable<Policy> policies,
|
||||
string orgId)
|
||||
{
|
||||
var resetPasswordPolicyOptions = new ResetPasswordPolicyOptions();
|
||||
|
||||
if (policies == null || orgId == null)
|
||||
{
|
||||
return new Tuple<ResetPasswordPolicyOptions, bool>(resetPasswordPolicyOptions, false);
|
||||
}
|
||||
|
||||
var policy = policies.FirstOrDefault(p =>
|
||||
p.OrganizationId == orgId && p.Type == PolicyType.ResetPassword && p.Enabled);
|
||||
resetPasswordPolicyOptions.AutoEnrollEnabled = GetPolicyBool(policy, "autoEnrollEnabled") ?? false;
|
||||
|
||||
return new Tuple<ResetPasswordPolicyOptions, bool>(resetPasswordPolicyOptions, policy != null);
|
||||
}
|
||||
|
||||
private int? GetPolicyInt(Policy policy, string key)
|
||||
{
|
||||
if (policy.Data.ContainsKey(key))
|
||||
|
||||
@@ -167,6 +167,19 @@ namespace Bit.Core.Services
|
||||
}
|
||||
return new Organization(organizations[id]);
|
||||
}
|
||||
|
||||
public async Task<Organization> GetOrganizationByIdentifierAsync(string identifier)
|
||||
{
|
||||
var userId = await GetUserIdAsync();
|
||||
var organizations = await GetAllOrganizationAsync();
|
||||
|
||||
if (organizations == null || organizations.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return organizations.FirstOrDefault(o => o.Identifier == identifier);
|
||||
}
|
||||
|
||||
public async Task<List<Organization>> GetAllOrganizationAsync()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user