This package provides a Swift implementation for authenticating with Google Cloud services. It's made for be a server-first solution instead of the official google-auth-library-swift.
let authorization = Authorization(scopes: ["https://www.googleapis.com/auth/cloud-platform"], eventLoopGroup: <#eventLoopGroup#>)
let accessToken = try await authorization.accessToken()
print(accessToken)
You can also implicitly use a specific method (aka provider) for authentication:
let authorization = Authorization(
scopes: ["https://www.googleapis.com/auth/cloud-platform"],
provider: ServiceAccountProvider(credentials: <#credentials#>),
eventLoopGroup: <#eventLoopGroup#>
)
The default provider can be configured globally by using the AuthorizationSystem
.
await AuthorizationSystem.bootstrap(
ServiceAccountProvider(credentials: <#credentials#>)
)
These are the currently supported authentication methods and default order of the default provider.
If GOOGLE_APPLICATION_CREDENTIALS
environment variabl is set, the service account JSON file will be used.
If ~/.config/gcloud/application_default_credentials.json
file exists, the Google Cloud SDK credentials will be used.
If running on Google Cloud Platform, the metadata server will be used to retrieve the credentials.