Ktor authentication provider for Firebase Auth module.
repositories {
mavenCentral()
}
dependencies {
implementation("com.kborowy:firebase-auth-provider:VERSION")
}
A Firebase project with Authentication module is required. See sample project to learn more.
install(Authentication) {
firebase("my-auth") {
realm = "My Server"
setup {
// required, see configuration below
}
validate { token ->
UserIdPrincipal(token.uid)
}
}
}
The authentication provider requires initialization of a FirebaseApp instance. You can either:
-
Provide an existing FirebaseApp instance, or
-
Initialize a new instance using a service account file
Provide a pre-configured FirebaseApp instance:
firebase("auth-firebase") {
setup {
firebaseApp = FirebaseApp.getInstance()
}
}
Provide a service account JSON file OR an InputStream
containing the service account credentials.
Optionally specify a firebaseAppName
to identify your Firebase instance.
firebase(name = "auth-firebase", firebaseAppName = "my-fb-app") {
setup {
// Choose one initialization method:
adminFile = File("path/to/admin/file.json")
// OR
adminFileStream = myFile.inputStream()
}
}
Param | Required | Description |
---|---|---|
validate | Required | Lambda receiving decoded and verified FirebaseToken, expected to return Principal, if user is authorized or null otherwise. |
realm | Optional | String describing the protected area or the scope of protection. This could be a message like "Access to the staging site" or similar, so that the user knows to which space they are trying to get access to. Defaults to "Ktor Server" |
Copyright 2023 Krzysztof Borowy
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.