-
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.
- Loading branch information
Showing
9 changed files
with
149 additions
and
147 deletions.
There are no files selected for viewing
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 | ||
} |
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
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 | ||
} |
49 changes: 49 additions & 0 deletions
49
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,49 @@ | ||
/* | ||
* Part of NDLA backend.common.main | ||
* Copyright (C) 2024 NDLA | ||
* | ||
* See LICENSE | ||
* | ||
*/ | ||
|
||
package no.ndla.common.model.domain.myndla.auth | ||
|
||
import no.ndla.common.model.domain.myndla.{ArenaGroup, MyNDLAUser} | ||
import sttp.model.headers.{AuthenticationScheme, WWWAuthenticateChallenge} | ||
import sttp.monad.MonadError | ||
import sttp.tapir.* | ||
import sttp.tapir.CodecFormat.TextPlain | ||
import sttp.tapir.EndpointInput.{AuthInfo, AuthType} | ||
import sttp.tapir.server.PartialServerEndpoint | ||
|
||
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
72 changes: 0 additions & 72 deletions
72
network/src/main/scala/no/ndla/network/tapir/auth/MyNDLAAuth.scala
This file was deleted.
Oops, something went wrong.