Skip to content

Commit

Permalink
Merge pull request #11 from fossapps/10-verify-secret-more-info
Browse files Browse the repository at this point in the history
feat(secretVerification): add more info
  • Loading branch information
cyberhck authored Dec 15, 2020
2 parents 578a239 + 614e7b2 commit 1cdc91e
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,7 @@ public async Task<IActionResult> Verify([FromHeader(Name = "Authorization")] [Re
{
var (appId, secret) = GetBasicAuthData(authorization);
var result = await _verifySecretService.Verify(appId, secret);
return Ok(new VerifySecretResponse
{
Success = result
});
return Ok(result);
}
catch (BadBasicAuthorizationDataException e)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ namespace Micro.AppRegistration.Api.VerifySecret
public class VerifySecretResponse
{
public bool Success { set; get; }
public string Owner { set; get; }
public string ShortCode { set; get; }
public bool Approved { set; get; }
public bool UseDefaultShortCode { set; get; }
}
}
14 changes: 11 additions & 3 deletions Micro.AppRegistration.Api/VerifySecret/VerifySecretService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Micro.AppRegistration.Api.VerifySecret
{
public interface IVerifySecretService
{
Task<bool> Verify(string appId, string secret);
Task<VerifySecretResponse> Verify(string appId, string secret);
}
public class VerifySecretService : IVerifySecretService
{
Expand All @@ -20,13 +20,21 @@ public VerifySecretService(IPasswordHasher<Application> secretHasher, IListAppli
_applicationRepository = applicationRepository;
}

public async Task<bool> Verify(string appId, string secret)
public async Task<VerifySecretResponse> Verify(string appId, string secret)
{
var application = await _applicationRepository.FindById(appId);
var result = _secretHasher.VerifyHashedPassword(null, application.Secret, secret);
// todo: if result returns a rehash needed, we need re-hash password and save it in database.
// to be done after MVP
return result == PasswordVerificationResult.Success || result == PasswordVerificationResult.SuccessRehashNeeded;
var success = result == PasswordVerificationResult.Success || result == PasswordVerificationResult.SuccessRehashNeeded;
return new VerifySecretResponse
{
Success = success,
Approved = application.Approved,
Owner = application.User,
ShortCode = application.ShortCode,
UseDefaultShortCode = application.UseDefaultCode
};
}
}
}

0 comments on commit 1cdc91e

Please sign in to comment.