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

GG-7813: openid-connect-userinfo : always enable addressLine5 & countryCode, remove unwanted code & config, and countryCode discovery [ GLSD-10273 ] #109

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

[![Build Status](https://travis-ci.org/hmrc/openid-connect-userinfo.svg?branch=master)](https://travis-ci.org/hmrc/openid-connect-userinfo) [ ![Download](https://api.bintray.com/packages/hmrc/releases/openid-connect-userinfo/images/download.svg) ](https://bintray.com/hmrc/releases/openid-connect-userinfo/_latestVersion)

This Beta REST API aims to provide a specification compliant OpenID Connect implementation. It allows consumers to access user details with consent and in the OpenID Connect UserInfo format.
The REST API, exposed by the HMRC API Platform as /userinfo to external clients, aims to provide a specification compliant OpenID Connect implementation. It allows consumers to access user details with consent and in the OpenID Connect UserInfo format.

A typical workflow would be:

Expand All @@ -15,10 +15,15 @@ User details data structures follow the OpenId Connect UserInfo specification (s

You can dive deeper into the documentation in the [API Developer Hub](https://developer.service.hmrc.gov.uk/api-documentation/docs/api#openid-connect-userinfo).

## Deprecated Class Usage
You can find the deprecation suppression `@nowarn("cat=deprecation")` in the code in few places.
## Authentication tokens
Note, the /userinfo endpoint is an external API endpoint. This endpoint requires an API token for authentication.

The reason is that when the latest `v2.Retrievals` was used then the integration tests were broken and wasn't obvious why.
## API

| Method | HMRC API Platform Path | Internal Path | Description |
|--------|------------------------|---------------|----------------------------------------------------------------------------------------------------------------------|
| GET | /userinfo | / | Returns information about an End-User as requested in the openid scopes as documented in the published API document. |
| POST | Internal use only | / | |

## Running Locally
Run the service `sbt run -Drun.mode=Dev`
Expand Down
45 changes: 0 additions & 45 deletions app/config/FeatureSwitch.scala

This file was deleted.

57 changes: 0 additions & 57 deletions app/controllers/testOnly/FeatureSwitchController.scala

This file was deleted.

23 changes: 8 additions & 15 deletions app/data/UserInfoGenerator.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package data
import javax.inject.Singleton
import java.time.LocalDate
import uk.gov.hmrc.auth.core.{Enrolment, EnrolmentIdentifier}
import config.UserInfoFeatureSwitches
import domain.{Address, GovernmentGatewayDetails, Mdtp, UserInfo}

import scala.util.Random.{nextInt => randomNextInt}
Expand Down Expand Up @@ -75,27 +74,21 @@ class UserInfoGenerator {
)
)

def addressWithToggleableFeatures(isAddressLine5: Boolean = false, isCountryCode: Boolean = false): Option[Address] = {
val addressLine5 = if (isAddressLine5) "\n|Line5" else ""
val code = if (isCountryCode) Some("GB") else None

def address: Option[Address] =
Some(
Address(
s"""221B Baker Street
|Town centre
|London
|England$addressLine5
|NW1 9NT
|Great Britain""".stripMargin,
|Town centre
|London
|England
|Line5
|NW1 9NT
|Great Britain""".stripMargin,
Some("NW1 9NT"),
Some("Great Britain"),
code
Some("GB")
)
)
}

def address: Option[Address] =
addressWithToggleableFeatures(UserInfoFeatureSwitches.addressLine5.isEnabled, UserInfoFeatureSwitches.countryCode.isEnabled)

val enrolments: Set[Enrolment] = Set(Enrolment("IR-SA", List(EnrolmentIdentifier("UTR", "174371121")), "Activated"))
private val government_gateway_v1_0: GovernmentGatewayDetails = GovernmentGatewayDetails(
Expand Down
7 changes: 2 additions & 5 deletions app/services/UserInfoTransformer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import javax.inject.Singleton
import java.time.LocalDate
import uk.gov.hmrc.auth.core.Enrolments
import uk.gov.hmrc.auth.core.retrieve.ItmpAddress
import config.UserInfoFeatureSwitches
import domain._

@Singleton
Expand All @@ -39,10 +38,8 @@ class UserInfoTransformer {

def address = if (scopes.contains("address")) {
val countryName = desUserInfo flatMap { c => c.address.countryName }
val countryCode = if (UserInfoFeatureSwitches.countryCode.isEnabled) { desUserInfo flatMap { u => u.address.countryCode } }
else None
val countryCode = desUserInfo flatMap { u => u.address.countryCode }
desUserInfo map (u => Address(formattedAddress(u.address), u.address.postCode, countryName, countryCode))

} else None

val identifier = if (scopes.contains("openid:gov-uk-identifiers")) authority flatMap (_.nino) else None
Expand Down Expand Up @@ -74,7 +71,7 @@ class UserInfoTransformer {

private def formattedAddress(desAddress: ItmpAddress) = {
val countryName = desAddress.countryName
val addressLine5 = if (UserInfoFeatureSwitches.addressLine5.isEnabled) desAddress.line5 else None
val addressLine5 = desAddress.line5
Seq(desAddress.line1, desAddress.line2, desAddress.line3, desAddress.line4, addressLine5, desAddress.postCode, countryName).flatten.mkString("\n")
}

Expand Down
9 changes: 0 additions & 9 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@ play.i18n.langs = ["en"]
# !!!WARNING!!! DO NOT CHANGE THIS ROUTER
play.http.router = prod.Routes

feature.addressLine5 = false
feature.countryCode = false

# Controller
# ~~~~~
# By default all controllers will have authorisation, logging and
Expand Down Expand Up @@ -84,12 +81,6 @@ controllers {
needsLogging = true
needsAuditing = false
}

controllers.testOnly.FeatureSwitchController = {
needsAuth = false
needsLogging = true
needsAuditing = false
}
}

# Root logger:
Expand Down
3 changes: 0 additions & 3 deletions conf/testOnlyDoNotUseInAppConf.routes
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
GET /test-only/feature-switches @controllers.testOnly.FeatureSwitchController.getFlags
POST /test-only/feature-switches @controllers.testOnly.FeatureSwitchController.setFlags

-> / prod.Routes
74 changes: 0 additions & 74 deletions it/test/FeatureSwitchControllerISpec.scala

This file was deleted.

15 changes: 0 additions & 15 deletions it/test/UserInfoServiceISpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import java.nio.file.Paths
import com.fasterxml.jackson.databind.ObjectMapper
import com.github.fge.jsonschema.core.report.LogLevel
import com.github.fge.jsonschema.main.JsonSchemaFactory
import config.{FeatureSwitch, UserInfoFeatureSwitches}
import domain._

import java.time.LocalDate
Expand All @@ -29,21 +28,7 @@ import uk.gov.hmrc.auth.core._
import uk.gov.hmrc.auth.core.retrieve._
import uk.gov.hmrc.domain.Nino

import scala.jdk.CollectionConverters.CollectionHasAsScala

class UserInfoServiceISpec extends BaseFeatureISpec with AuthStub with ThirdPartyDelegatedAuthorityStub {

override def beforeAll(): Unit = {
super.beforeAll()
FeatureSwitch.enable(UserInfoFeatureSwitches.countryCode)
FeatureSwitch.enable(UserInfoFeatureSwitches.addressLine5)
}
override def afterAll(): Unit = {
super.afterAll()
FeatureSwitch.disable(UserInfoFeatureSwitches.countryCode)
FeatureSwitch.disable(UserInfoFeatureSwitches.addressLine5)
}

val serviceUrl: String = resource("")

val authorizationTokens = "AUTHORIZATION_TOKENS"
Expand Down
18 changes: 4 additions & 14 deletions project/AppDependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import sbt.*

object AppDependencies {

private val bootstrapPlayVersion = "8.5.0"
private val bootstrapPlayVersion = "8.6.0"

private val compile: Seq[ModuleID] = Seq(
ws,
Expand All @@ -14,19 +14,9 @@ object AppDependencies {
)

private val test: Seq[ModuleID] = Seq(
"org.scalatest" %% "scalatest" % "3.2.17" % Test,
"org.scalatestplus" %% "scalacheck-1-17" % "3.2.17.0" % Test,
"org.scalatestplus.play" %% "scalatestplus-play" % "5.1.0" % Test,
"org.playframework" %% "play-test" % PlayVersion.current % Test,
"com.github.tomakehurst" % "wiremock" % "2.27.2" % Test,
"uk.gov.hmrc" %% "bootstrap-test-play-30" % bootstrapPlayVersion % Test,
"org.pegdown" % "pegdown" % "1.6.0" % Test,
"org.jsoup" % "jsoup" % "1.17.2" % Test,
"org.scalaj" %% "scalaj-http" % "2.4.2" % Test,
"org.mockito" %% "mockito-scala-scalatest" % "1.17.30" % Test,
"org.scalacheck" %% "scalacheck" % "1.17.0" % Test,
"com.github.java-json-tools" % "json-schema-validator" % "2.2.14" % Test,
"com.vladsch.flexmark" % "flexmark-all" % "0.64.0" % Test
"org.scalaj" %% "scalaj-http" % "2.4.2" % Test,
"com.github.java-json-tools" % "json-schema-validator" % "2.2.14" % Test,
"uk.gov.hmrc" %% "bootstrap-test-play-30" % "8.6.0" % Test
)

def apply(): Seq[ModuleID] = compile ++ test
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=1.9.7
sbt.version=1.9.9
6 changes: 3 additions & 3 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ resolvers += "HMRC-open-artefacts-maven" at "https://open.artefacts.tax.service.
resolvers += Resolver.url("HMRC-open-artefacts-ivy", url("https://open.artefacts.tax.service.gov.uk/ivy2"))(Resolver.ivyStylePatterns)


addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.20.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-auto-build" % "3.22.0")
addSbtPlugin("uk.gov.hmrc" % "sbt-distributables" % "2.5.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.11")
addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.2")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.12")
addSbtPlugin("org.playframework" % "sbt-plugin" % "3.0.3")
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0" exclude("org.scala-lang.modules", "scala-xml_2.12"))
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.2")
Loading