Closed inv-sarathk closed 2 years ago
Hello @Sarath222K thanks for reporting this issue.
A quick follow up here, can you share the awsAPIPlugin
section in amplifyconfiguration.dart
?
Hello @Sarath222K thanks for reporting this issue.
A quick follow up here, can you share the
awsAPIPlugin
section inamplifyconfiguration.dart
?
Yeah sure,
const amplifyconfig = ''' {
"UserAgent": "aws-amplify-cli/2.0",
"Version": "1.0",
"api": {
"plugins": {
"awsAPIPlugin": {
“Test”: {
"endpointType": "GraphQL",
"endpoint": "https://XXXXXXXXXXXXXX.appsync-api.ap-northeast-1.amazonaws.com/graphql",
"region": "ap-northeast-1",
"authorizationType": "API_KEY",
"apiKey": “XXXXXXXXXXXXXXXXX”
},
"TestREST": {
"endpointType": "REST",
"endpoint": “XXXXXXXXXXXXXXX.execute-api.ap-northeast-1.amazonaws.com/dev",
"region": "ap-northeast-1",
"authorizationType": "AWS_IAM"
}
}
}
},
"auth": {
"plugins": {¯
"awsCognitoAuthPlugin": {
"UserAgent": "aws-amplify-cli/0.1.0",
"Version": "0.1.0",
"IdentityManager": {
"Default": {}
},
"CredentialsProvider": {
"CognitoIdentity": {
"Default": {
"PoolId": "ap-northeast-1:XXXXXXXXXXXXXXXXXXX”,
"Region": "ap-northeast-1"
}
}
},
"CognitoUserPool": {
"Default": {
"PoolId": "ap-northeast-XXXXXXXXXXXXXX”,
"AppClientId": “XXXXXXXXXXXXXXXXXXXX”,
"Region": "ap-northeast-1"
}
},
"Auth": {
"Default": {
"authenticationFlowType": "USER_SRP_AUTH",
"socialProviders": [],
"usernameAttributes": [],
"signupAttributes": [
"PHONE_NUMBER"
],
"passwordProtectionSettings": {
"passwordPolicyMinLength": 8,
"passwordPolicyCharacters": [
"REQUIRES_LOWERCASE",
"REQUIRES_NUMBERS",
"REQUIRES_SYMBOLS",
"REQUIRES_UPPERCASE"
]
},
"mfaConfiguration": "OFF",
"mfaTypes": [
"SMS"
],
"verificationMechanisms": [
"PHONE_NUMBER"
]
}
},
"AppSync": {
"Default": {
"ApiUrl": “XXXXXXXXXXXXXXXXXXX.appsync-api.ap-northeast-1.amazonaws.com/graphql",
"Region": "ap-northeast-1",
"AuthMode": "API_KEY",
"ApiKey": “XXXXXXXXXXXXXXXXXXX”,
"ClientDatabasePrefix": “XXXXXXX_API_KEY"
},
"Socrates_AWS_IAM": {
"ApiUrl": “XXXXXXXXXXXXXXXXXXXXXXX.appsync-api.ap-northeast-1.amazonaws.com/graphql",
"Region": "ap-northeast-1",
"AuthMode": "AWS_IAM",
"ClientDatabasePrefix": “XXXXXXXXXX_AWS_IAM"
}
}
}
}
}
}''';
Hi @Sarath222K thanks for provide the info.
Looking at your amplify configuration, your REST API uses IAM
as authorization strategy.
"TestREST": {
"endpointType": "REST",
"endpoint": "XXXXXXXXXXXXXXX.execute-api.ap-northeast-1.amazonaws.com/dev",
"region": "ap-northeast-1",
"authorizationType": "AWS_IAM"
}
According to the document when using IAM
the credential should be automatically attached to request headers according to you configuration.
Where do you get the token shown in your code example? If you are using something custom, you may need to follow this instruction to enable custom headers for your API Gateway.
we have configured our backend rest api with "authorizationType": "AMAZON_COGNITO_USER_POOLS", but our configuration(amplifyconfiguration.dart) file is not getting updated even after 'amplify pull', the authorizarion type is still IAM user as above
The document suggests that a manual change is required to apply cognito user pool auth to REST API. Have you tried these steps?
@Sarath222K Have you tried the steps @HuiSF referenced above?
Tried, but app is crashing after manually changing the configuration to "authorizationType": "AMAZON_COGNITO_USER_POOLS" inside awsconfiguration.dart file .
@Sarath222K Have you tried the steps @HuiSF referenced above?
Tried but the app is crashing after applying manually
@Sarath222K - Can you share the log output when the app crashes?
Hi @inv-sarathk
I am closing this issue for now as we didn't hear from you We can reopen it if you are still facing the issue and when you provide the details
Regards Mo
Description
When I try to add a header authorization through amplify api package i am getting an error response 401 with a message unauthorized on the api call. When I checked on the backend the header is not reaching there. This is the code I tried :
try { RestOptions options = const RestOptions(path: '/test', headers: {'Authorization': 'token'}); RestOperation restOperation = Amplify.API.get(restOptions: options); RestResponse response = await restOperation.response; print('GET call succeeded'); print(response); } on ApiException catch (e) { print('GET call failed: $e'); }
Categories
Steps to Reproduce
No response
Screenshots
No response
Platforms
Environment
Dependencies
Device
Pixel 5(Emulator)
OS
Android 13
CLI Version
7.6.26
Additional Context
No response