-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
learningpath-api: Allow feide authentication
This patch introduces feide authentication to the learningpath-api wherever authentication is required.
- Loading branch information
Showing
76 changed files
with
976 additions
and
669 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 3 additions & 4 deletions
7
...ndla/myndlaapi/model/api/MyNDLAUser.scala → .../common/model/api/myndla/MyNDLAUser.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
common/src/main/scala/no/ndla/common/model/domain/myndla/ArenaGroup.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Part of NDLA common | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
*/ | ||
|
||
package no.ndla.common.model.domain.myndla | ||
|
||
import com.scalatsi.TypescriptType.{TSLiteralString, TSUnion} | ||
import com.scalatsi.{TSNamedType, TSType} | ||
import enumeratum.* | ||
|
||
sealed trait ArenaGroup extends EnumEntry | ||
object ArenaGroup extends Enum[ArenaGroup] with CirceEnum[ArenaGroup] { | ||
case object ADMIN extends ArenaGroup | ||
override def values: IndexedSeq[ArenaGroup] = findValues | ||
|
||
implicit val enumTsType: TSNamedType[ArenaGroup] = | ||
TSType.alias[ArenaGroup]("ArenaGroup", TSUnion(values.map(e => TSLiteralString(e.entryName)))) | ||
} |
6 changes: 3 additions & 3 deletions
6
...myndlaapi/model/domain/FolderStatus.scala → ...on/model/domain/myndla/FolderStatus.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
common/src/main/scala/no/ndla/common/model/domain/myndla/MyNDLAGroup.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Part of NDLA common | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
* | ||
*/ | ||
|
||
package no.ndla.common.model.domain.myndla | ||
|
||
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} | ||
import io.circe.{Decoder, Encoder} | ||
|
||
case class MyNDLAGroup( | ||
id: String, | ||
displayName: String, | ||
isPrimarySchool: Boolean, | ||
parentId: Option[String] | ||
) | ||
|
||
object MyNDLAGroup { | ||
implicit val encoder: Encoder[MyNDLAGroup] = deriveEncoder | ||
implicit val decoder: Decoder[MyNDLAGroup] = deriveDecoder | ||
} |
40 changes: 40 additions & 0 deletions
40
common/src/main/scala/no/ndla/common/model/domain/myndla/MyNDLAUser.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Part of NDLA common | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
*/ | ||
|
||
package no.ndla.common.model.domain.myndla | ||
|
||
import io.circe.{Decoder, Encoder} | ||
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} | ||
import no.ndla.common.model.NDLADate | ||
|
||
case class MyNDLAUser( | ||
id: Long, | ||
feideId: String, | ||
favoriteSubjects: Seq[String], | ||
userRole: UserRole.Value, | ||
lastUpdated: NDLADate, | ||
organization: String, | ||
groups: Seq[MyNDLAGroup], | ||
username: String, | ||
displayName: String, | ||
email: String, | ||
arenaEnabled: Boolean, | ||
arenaGroups: List[ArenaGroup], | ||
shareName: Boolean | ||
) { | ||
// Keeping FEIDE and our data in sync | ||
def wasUpdatedLast24h: Boolean = NDLADate.now().isBefore(lastUpdated.minusSeconds(10)) | ||
|
||
def isStudent: Boolean = userRole == UserRole.STUDENT | ||
def isTeacher: Boolean = userRole == UserRole.EMPLOYEE | ||
def isAdmin: Boolean = arenaGroups.contains(ArenaGroup.ADMIN) | ||
} | ||
|
||
object MyNDLAUser { | ||
implicit val encoder: Encoder[MyNDLAUser] = deriveEncoder | ||
implicit val decoder: Decoder[MyNDLAUser] = deriveDecoder | ||
} |
50 changes: 50 additions & 0 deletions
50
common/src/main/scala/no/ndla/common/model/domain/myndla/MyNDLAUserDocument.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Part of NDLA common | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
* | ||
*/ | ||
|
||
package no.ndla.common.model.domain.myndla | ||
|
||
import io.circe.{Decoder, Encoder} | ||
import io.circe.generic.semiauto.{deriveDecoder, deriveEncoder} | ||
import no.ndla.common.model.NDLADate | ||
|
||
case class MyNDLAUserDocument( | ||
favoriteSubjects: Seq[String], | ||
userRole: UserRole.Value, | ||
lastUpdated: NDLADate, | ||
organization: String, | ||
groups: Seq[MyNDLAGroup], | ||
username: String, | ||
displayName: String, | ||
email: String, | ||
arenaEnabled: Boolean, | ||
arenaGroups: List[ArenaGroup], | ||
shareName: Boolean | ||
) { | ||
def toFullUser(id: Long, feideId: String): MyNDLAUser = { | ||
MyNDLAUser( | ||
id = id, | ||
feideId = feideId, | ||
favoriteSubjects = favoriteSubjects, | ||
userRole = userRole, | ||
lastUpdated = lastUpdated, | ||
organization = organization, | ||
groups = groups, | ||
username = username, | ||
displayName = displayName, | ||
email = email, | ||
arenaEnabled = arenaEnabled, | ||
shareName = shareName, | ||
arenaGroups = arenaGroups | ||
) | ||
} | ||
} | ||
|
||
object MyNDLAUserDocument { | ||
implicit val encoder: Encoder[MyNDLAUserDocument] = deriveEncoder | ||
implicit val decoder: Decoder[MyNDLAUserDocument] = deriveDecoder | ||
} |
5 changes: 2 additions & 3 deletions
5
...dla/myndlaapi/model/domain/UserRole.scala → ...common/model/domain/myndla/UserRole.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
common/src/main/scala/no/ndla/common/model/domain/myndla/auth/AuthUtility.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Part of NDLA backend.common.main | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
* | ||
*/ | ||
|
||
package no.ndla.common.model.domain.myndla.auth | ||
|
||
import sttp.model.headers.{AuthenticationScheme, WWWAuthenticateChallenge} | ||
import sttp.tapir.* | ||
import sttp.tapir.CodecFormat.TextPlain | ||
import sttp.tapir.EndpointInput.{AuthInfo, AuthType} | ||
|
||
import scala.collection.immutable.ListMap | ||
|
||
object AuthUtility { | ||
private val authScheme = AuthenticationScheme.Bearer.name | ||
private def filterHeaders(headers: List[String]) = headers.filter(_.toLowerCase.startsWith(authScheme.toLowerCase)) | ||
private def stringPrefixWithSpace = Mapping.stringPrefixCaseInsensitiveForList(authScheme + " ") | ||
val feideTokenAuthCodec: Codec[List[String], Option[String], TextPlain] = { | ||
val codec = implicitly[Codec[List[String], Option[String], CodecFormat.TextPlain]] | ||
Codec | ||
.id[List[String], CodecFormat.TextPlain](codec.format, Schema.binary) | ||
.map(filterHeaders(_))(identity) | ||
.map(stringPrefixWithSpace) | ||
.mapDecode(codec.decode)(codec.encode) | ||
.schema(codec.schema) | ||
} | ||
|
||
def feideOauth() = { | ||
val authType: AuthType.ScopedOAuth2 = EndpointInput.AuthType | ||
.OAuth2(None, None, ListMap.empty, None) | ||
.requiredScopes(Seq.empty) | ||
|
||
EndpointInput.Auth( | ||
input = sttp.tapir.header("FeideAuthorization")(feideTokenAuthCodec), | ||
challenge = WWWAuthenticateChallenge.bearer, | ||
authType = authType, | ||
info = AuthInfo.Empty.securitySchemeName("oauth2") | ||
) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.