-
Notifications
You must be signed in to change notification settings - Fork 198
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need to pass API-Key dynamically through APIPlugins in iOS #3790
Comments
This has been identified as a feature request. If this feature is important to you, we strongly encourage you to give a 👍 reaction on the request. This helps us prioritize new features most important to you. Thank you! |
If it a feature request, can i aspect any solution from your end please. I need to implement it in my current project. |
Hi @Santosh2332, thanks for opening this. I'm a bit confused by what you're describing. API Key and OpenID Connect (OIDC) are two separate and independent Authorization Types supported by AppSync. Could you please clarify your use case, or what are you trying to achieve? Perhaps unrelated, but you've mentioned adding the |
Hi @ruisebas thanks for the reply. I am using API_Key as authorization type for configuration that is configure in amplifyconfiguration.json file. |
If you're relying on the What you can do is create your own Here's a simple example: let apiKey: JSONValue = "YOUR API KEY"
let configuration = AmplifyConfiguration(
api: .init(plugins: [
"awsAPIPlugin" : [
"[API NAME]": [
"endpointType": "ENDPOINT TYPE]",
"endpoint": "[ENDPOINT URL]",
"region": "[REGION]",
"authorizationType": "API_KEY",
"apiKey": apiKey
]
]
]),
// Add the remaining categories...
)
try Amplify.add(plugin: AWSAPIPlugin())
// Add the remaining plugins
try Amplify.configure(configuration) Alternatively, if you don't want to manually recreate the whole file because you have lots of plugins and/or properties, you can just parse the struct MyConfiguration: Decodable {
// You can omit categories that you don't use
var analytics: AnalyticsCategoryConfiguration?
var api: APICategoryConfiguration?
var auth: AuthCategoryConfiguration?
var dataStore: DataStoreCategoryConfiguration?
var geo: GeoCategoryConfiguration?
var hub: HubCategoryConfiguration?
var logging: LoggingCategoryConfiguration?
var notifications: NotificationsCategoryConfiguration?
var predictions: PredictionsCategoryConfiguration?
var storage: StorageCategoryConfiguration?
init() throws {
guard let url = Bundle.main.url(forResource: "amplifyconfiguration", withExtension: "json") else {
throw ConfigurationError.invalidAmplifyConfigurationFile(
"Unable to read amplifyconfiguration.json",
"Make sure the file is present in the bundle"
)
}
let data = try Data(contentsOf: url)
self = try JSONDecoder().decode(MyConfiguration.self, from: data)
}
func createAmplifyConfiguration() -> AmplifyConfiguration {
return .init(
analytics: analytics,
api: api,
auth: auth,
dataStore: dataStore,
geo: geo,
hub: hub,
logging: logging,
notifications: notifications,
predictions: predictions,
storage: storage
)
}
} let apiKey: JSONValue = "YOUR API KEY"
var configuration = try MyConfiguration()
// Overwrite only the API category configuration, there's no need to do anything for the remaining ones
configuration.api = .init(plugins: [
"awsAPIPlugin" : [
"[API NAME]": [
"endpointType": "ENDPOINT TYPE]",
"endpoint": "[ENDPOINT URL]",
"region": "[REGION]",
"authorizationType": "API_KEY",
"apiKey": apiKey
]
]
])
try Amplify.add(plugin: AWSAPIPlugin())
// Add the remaining plugins
try Amplify.configure(configuration.createAmplifyConfiguration()) |
@ruisebas Thank you. |
This issue is now closed. Comments on closed issues are hard for our team to see. |
Is your feature request related to a problem? Please describe.
I have added awsconfiguration.json file in my project for configuration, now i need to pass API Key dynamically to configure amplify like below code(OIDC Auth)
Is there Any way to configure API-Key from my end like above example.
Describe the solution you'd like
Need to configure API-Key from project Swift class
Describe alternatives you've considered
Provide any alternative from your end
Is the feature request related to any of the existing Amplify categories?
API
Additional context
No response
The text was updated successfully, but these errors were encountered: