Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google auth #103

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

TerezaSkutova
Copy link
Contributor

Summary

The authentication is resolved by Google API on Google Cloud and it is allowing accounts only from our domain (@3pillarglobal.com). If you try to login with another email address, you will get an error 403.

There is created a user record on database for each new logged user. The model contains:

  • google ID
  • first name
  • last name
  • username
  • email address
  • URL for the profile image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • Refactoring (non-breaking change to code and structure)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Testing

I have been testing this feature on my account.

There is added a new use case for login/logout. The database is extended by a user model where are situated claims from google API for auth.
@TerezaSkutova TerezaSkutova linked an issue May 11, 2022 that may be closed by this pull request
3 tasks
Copy link
Member

@PlesnikJakub PlesnikJakub left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, @TerezaSkutova overall you did a pretty good job, there are just a couple of small tweaks we need to do before it will be ready for merge. 😊


public interface IUserRepository : IGenericRepository<UserModel, IEntity>
{
Task<UserModel> GetUserByGoogleId(string id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: provider Id would be optional in case of future extensibility. Coupling names to a specific platform or tool should be avoided if possible.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it applies across the whole solution.

claim.Value
}).ToDictionary(claim => claim.Type.Substring(claim.Type.LastIndexOf("/") + 1), claim => claim.Value);

var input = new EnsureCreatedUserInput
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this solution, the attributes are unprotected from malicious or malformed input.

You can extend input to provide some sort of domain validation on important attributes.
Or instead of casting values to the dictionary cast them to objects so, we can use data attributes.

add validation also to others attributes.

"Google": {
"ClientID": "172955704257-ug7p7mbjrd7ogkegvjfldnofal57q11b.apps.googleusercontent.com",
"ClientSecret": "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"
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be here 🙈 we can fill value in the pipeline if needed.
⚠️ ⚠️ ⚠️ if its really a secret please remove it also from a git history with an interactive rebase ⚠️ ⚠️ ⚠️

}

[HttpGet(Name = "Login")]
public async Task Login()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 2 methods in one controller could we split it? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is closely related to Login method. Does it really make sense?

public UserRepository(MyDbContext context, IMapper mapper) : base(context, mapper)
{
}
public async Task<UserModel> GetUserByGoogleId(string googleId)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

check warning 👇


if (model is null)
{
_outputPort.Invalid();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment: I noticed this earlier. You can pick new names for methods in the output port. Sometimes invalid makes sense but could be Failed, NotFound, Corrupted, anything that comes to your mind for a given context. 😊

{
var user = await _userRepository.GetUserByGoogleId(input.GoogleId);

if(user is null)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we use the return early principle in this case? 🤔

There is added a new use case for login/logout. The database is extended by a user model where are situated claims from google API for auth.
….com:3PillarGlobal-Czechia/interview-app-api into feature/74-spike-create-poc-for-google-oauth
@sonarcloud
Copy link

sonarcloud bot commented May 23, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

97.7% 97.7% Coverage
0.0% 0.0% Duplication

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Spike: create PoC for Google OAuth
2 participants