Class GitHubVerifiedEmailLookup

java.lang.Object
com.irurueta.authserver.authorization.infrastructure.github.GitHubVerifiedEmailLookup
All Implemented Interfaces:
VerifiedEmailLookup

@Component public class GitHubVerifiedEmailLookup extends Object implements VerifiedEmailLookup
VerifiedEmailLookup over GitHub's GET /user/emails, called through the client generated from apis/github/rest-server/github-api-v1.yaml. The email of GitHub's profile is whatever the user chose to show and is not verified, so the address is read from that endpoint, which flags each address as primary and verified.

The base URI of the API is the user-info URI of the registration without its trailing /user (by default https://api.github.com), so a GitHub Enterprise registration, or the fake provider of the tests, is called where it is. Every failure (GitHub unreachable, an error status, an unreadable body, a user-info URI of another shape) means "no verified address", which refuses the sign-in; it is logged without the token or anything of the user.

  • Field Details

    • USER_PATH

      static final String USER_PATH
      Path of the user endpoint below the base URI of GitHub's API.
      See Also:
    • usersApiFactory

      private final GitHubUsersApiFactory usersApiFactory
      Builds the generated client of each call.
    • emailMapper

      private final GitHubEmailMapper emailMapper
      Picks the verified primary address.
  • Constructor Details

    • GitHubVerifiedEmailLookup

      public GitHubVerifiedEmailLookup()
  • Method Details

    • verifiedPrimaryEmail

      public Optional<String> verifiedPrimaryEmail(String userInfoUri, String accessToken)
      Finds the verified primary address.
      Specified by:
      verifiedPrimaryEmail in interface VerifiedEmailLookup
      Parameters:
      userInfoUri - URI of GitHub's user endpoint, as the registration configures it.
      accessToken - GitHub access token of the user.
      Returns:
      the address, or an empty optional when there is none or GitHub cannot tell.
    • basePathOf

      private static Optional<String> basePathOf(String userInfoUri)
      Derives the base URI of the API from the user-info URI.
      Parameters:
      userInfoUri - URI of the user endpoint, possibly null.
      Returns:
      the URI without its trailing /user (and slashes), or an empty optional when it does not end so.