forked from loafle/openapi-generator-original
Merge pull request #263 from wordnik/basic-auth
Adds Basic auth as an authentication mechanism
This commit is contained in:
commit
2fd29d74f2
@ -21,6 +21,7 @@ libraryDependencies ++= Seq(
|
|||||||
"org.json4s" %% "json4s-jackson" % "3.2.10",
|
"org.json4s" %% "json4s-jackson" % "3.2.10",
|
||||||
"io.backchat.inflector" %% "scala-inflector" % "1.3.5",
|
"io.backchat.inflector" %% "scala-inflector" % "1.3.5",
|
||||||
"commons-io" % "commons-io" % "2.3",
|
"commons-io" % "commons-io" % "2.3",
|
||||||
|
"net.iharder" % "base64" % "2.3.8",
|
||||||
"ch.qos.logback" % "logback-classic" % "1.0.13" % "provided",
|
"ch.qos.logback" % "logback-classic" % "1.0.13" % "provided",
|
||||||
"org.rogach" %% "scallop" % "0.9.5",
|
"org.rogach" %% "scallop" % "0.9.5",
|
||||||
"junit" % "junit" % "4.11" % "test",
|
"junit" % "junit" % "4.11" % "test",
|
||||||
|
@ -1 +1 @@
|
|||||||
sbt.version=0.13.0
|
sbt.version=0.13.5
|
@ -28,6 +28,7 @@ import com.wordnik.swagger.util.ValidationException
|
|||||||
|
|
||||||
import java.io.{ File, FileWriter }
|
import java.io.{ File, FileWriter }
|
||||||
|
|
||||||
|
import net.iharder.Base64
|
||||||
import org.json4s.jackson.JsonMethods._
|
import org.json4s.jackson.JsonMethods._
|
||||||
import org.json4s.jackson.Serialization.write
|
import org.json4s.jackson.Serialization.write
|
||||||
|
|
||||||
@ -187,18 +188,20 @@ abstract class BasicGenerator extends CodegenConfig with PathUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def authenticate(apiKey: Option[String]): Option[ApiKeyValue] = {
|
def authenticate(apiKey: Option[String]): Option[ApiKeyValue] = {
|
||||||
Option(System.getProperty("header")) match {
|
val headerAuth = sys.props.get("header") map { e =>
|
||||||
case Some(e) => {
|
|
||||||
// this is ugly and will be replaced with proper arg parsing like in ScalaAsyncClientGenerator soon
|
// this is ugly and will be replaced with proper arg parsing like in ScalaAsyncClientGenerator soon
|
||||||
val authInfo = e.split(":")
|
val authInfo = e.split(":")
|
||||||
Some(ApiKeyValue(authInfo(0), "header", authInfo(1)))
|
ApiKeyValue(authInfo(0), "header", authInfo(1))
|
||||||
}
|
}
|
||||||
case _ => {
|
val basicAuth = sys.props.get("auth.basic") map { e =>
|
||||||
apiKey.map{ key =>
|
val creds = if (e.contains(":")) Base64.encodeBytes(e.getBytes) else e
|
||||||
Some(ApiKeyValue("api_key", "query", key))
|
ApiKeyValue("Authorization", "header", s"Basic $creds")
|
||||||
}.getOrElse(None)
|
|
||||||
}
|
}
|
||||||
|
val apiKeyAuth = apiKey map { key =>
|
||||||
|
ApiKeyValue("api_key", "query", key)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
headerAuth orElse basicAuth orElse apiKeyAuth
|
||||||
}
|
}
|
||||||
|
|
||||||
def extractApiOperations(apiListings: List[ApiListing], allModels: HashMap[String, Model] )(implicit basePath:String) = {
|
def extractApiOperations(apiListings: List[ApiListing], allModels: HashMap[String, Model] )(implicit basePath:String) = {
|
||||||
|
@ -44,3 +44,4 @@ case class AuthorizationCodeGrant(
|
|||||||
|
|
||||||
trait AuthorizationValue
|
trait AuthorizationValue
|
||||||
case class ApiKeyValue(keyName: String, passAs: String, value: String) extends AuthorizationValue
|
case class ApiKeyValue(keyName: String, passAs: String, value: String) extends AuthorizationValue
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user