Skip to content

Feature: External Login through OIDC #169

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

Merged
merged 82 commits into from
Feb 26, 2024
Merged

Conversation

tuj
Copy link
Contributor

@tuj tuj commented Nov 9, 2023

Link to ticket

https://jira.itkdev.dk/browse/DISPLAY-993

Description

  • Adds "external" openid-connect provider.
  • Renamed "oidc" openid-connect provider to "internal".
  • Modifies User to support external user type.
  • Adds command to set user type.
  • Expands api with external user endpoints.
  • Upgrades openid-connect bundle to 3.1 to support multiple providers.
  • Changes php requirement in composer.json to >= 8.1.
  • Changed user identifier to providerId.

NB! Uses the changes from #163 since support for multiple providers is necessary.

Screenshots

Screenshot 2023-10-04 at 12 17 01

Checklist

  • My code is covered by test cases.
  • My code passes our test (all our tests).
  • My code passes our static analysis suite.
  • My code passes our continuous integration process.

tuj added 30 commits August 26, 2023 08:08
@tuj tuj self-assigned this Dec 11, 2023
@tuj tuj added the enhancement New feature or request label Jan 7, 2024
@tuj tuj changed the title Feature/external login Feature: External Login through OIDC Jan 12, 2024
@tuj tuj requested a review from turegjorup January 15, 2024 09:09

namespace App\Dto;

class EmptyDTO
Copy link
Contributor

Choose a reason for hiding this comment

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

"EmptyDTO" ??? A short comment to explain use would be nice

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added comment.

.env Outdated
OIDC_CLIENT_SECRET=ADMIN_APP_CLIENT_SECRET
OIDC_REDIRECT_URI=ADMIN_APP_REDIRECT_URI
OIDC_LEEWAY=30
# ad provider
Copy link
Contributor

Choose a reason for hiding this comment

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

ad is specific to our planned use. We should stick to only using internal and external as terms

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

CHANGELOG.md Outdated
@@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

- [#162](https://github.com/os2display/display-api-service/pull/162)
- Adds "external" openid-connect provider.
- Renamed "oidc" openid-connect provider to "ad".
Copy link
Contributor

Choose a reason for hiding this comment

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

See above about ad

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

private ?\DateTimeImmutable $codeExpire;

#[ORM\Column(type: Types::STRING, nullable: false)]
private ?string $username;
Copy link
Contributor

Choose a reason for hiding this comment

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

Unique constraint? Would it ever make sense to have two codes for the same user?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you have invitations to two different Tenants


// Check if user exists already - if not create a user
$user = $this->entityManager->getRepository(User::class)->findOneBy(['email' => $email]);
$user = $this->entityManager->getRepository(User::class)->findOneBy(['providerId' => $providerId]);

if (null === $user) {
// Create the new user and persist it
$user = new User();
$user->setCreatedBy('OIDC');
Copy link
Contributor

Choose a reason for hiding this comment

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

Should 'OIDC' be changed to one of the UserTypeEnum values, or should we have different enum?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added enum

@@ -216,9 +216,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
// create the user and hash its password
$user = new User();
$user->setEmail($email);
$user->setProviderId($email);
$user->setFullName($fullName);
$user->setProvider(self::class);
$user->setCreatedBy('CLI');
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have an enum for 'CLI'?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added enum


namespace App\Utils;

class Roles
Copy link
Contributor

Choose a reason for hiding this comment

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

Enum?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What we want as output is a string so this is easier to use I think

@@ -70,6 +74,7 @@ protected function getAuthenticatedClient(string $role = 'ROLE_EDITOR'): Client

$user->addUserRoleTenant($userRoleTenant);

$manager->persist($userRoleTenant);
Copy link
Contributor

Choose a reason for hiding this comment

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

Should not be necessary because User has cascade: ['persist', ... on the relation

    #[ORM\OneToMany(targetEntity: UserRoleTenant::class, mappedBy: 'user', cascade: ['persist', 'remove'], orphanRemoval: true)]
    private Collection $userRoleTenants;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@tuj tuj requested a review from turegjorup January 16, 2024 17:03
@turegjorup turegjorup merged commit 674df81 into develop Feb 26, 2024
@turegjorup turegjorup deleted the feature/external-login branch February 26, 2024 08:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants