DRF Api-Key missing Attribute - django

I am trying to use the DRF Api Key mechanism for authentication, after following the guide here:
https://florimondmanca.github.io/djangorestframework-api-key/guide/
I receive nothing but errors, does someone have a working example or see what i am doing wrong here?
Global Settings:
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [
'rest_framework_api_key.permissions.HasAPIKey'
]
}
Tested in a class view also
class TestingApiKey(APIView):
permission_classes = [IsAuthenticated | HasAPIKey]
def post(self, request):```
3 sample curl requests:
Example 1
curl --location --request POST 'http://127.0.0.1:8000/api/test' \
--header 'Authorization: Api-Key TiJwEHau.MF4ov6E3iz3C9KNNRAGdryH1tXfkjz8r' \
--header 'Content-Type: application/json' \
--data-raw '{
"username" : "Testing",
"Password" : "Testing123"
}'
Example 2:
curl --location --request POST 'http://127.0.0.1:8000/api/test' \
--header 'Api-Key TiJwEHau.MF4ov6E3iz3C9KNNRAGdryH1tXfkjz8r' \
--header 'Content-Type: application/json' \
--data-raw '{
"username" : "Testing",
"Password" : "Testing123"
}'
Example 3
curl --location --request POST 'http://127.0.0.1:8000/api/test' \
--header 'X-Api-Key: Api-Key TiJwEHau.MF4ov6E3iz3C9KNNRAGdryH1tXfkjz8r' \
--header 'Content-Type: application/json' \
--data-raw '{
"username" : "Testing",
"Password" : "Testing123"
}'
Each test I carry out returns a 500 server error with the response:
'HasAPIKey' object has no attribute 'authenticate'
Anyone had this issue or understand why I would get this?

Ok, this has to do with adding global settings in the settings.py file.
I went back and commented out the following in the settings.py
"""
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': [,
'rest_framework_api_key.permissions.HasAPIKey'
]
}
"""
Once done I then added the following class object and everything worked fine.
permission_classes = [IsAuthenticated | HasAPIKey]

Related

Getting {"error": "invalid_grant" } in Django OAUTH when trying to generate a token using AUTHORIZATION CODE FLOW

I'm trying to access token using authorization code flow. I'm using authorization_code as the grant type.
Following documentation at Django OAuth
Here's my code that's making the post request:
curl --location --request POST 'http://127.0.0.1:8000/o/token/' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--header 'Cache-Control: no-cache' \
--header 'Accept: application/json' \
--data-urlencode 'client_id=ngta3GGa3jP6Rmv5Tspj97Bk4aiitHgv1EQilCDS' \
--data-urlencode 'client_secret=zLwMyuXg7WCSFwUDYBxFP3QxHh5mF6xM2hBsKyvRbypac5lV7fl2NoFeeDG3afWWxLedA7qtzD2Mvf68qyBra3A4iUXXlDXJO4LvxuZv4UULU6NLWlObpD0ylQSXbwZD' \
--data-urlencode 'code=q4NfBMbyTNbcIQZ4j7SfgMWL898psv' \
--data-urlencode 'redirect_uri=http://localhost:8000/no/callback/' \
--data-urlencode 'code_verifier=b'\''SlJDWEgyRzNYMks0RTVQVDlRVkFaOFdDUkxHV1A3QURMTjNITFdaMTBLU0tWQkkzMUVWVEZFU0k='\''' \
--data-urlencode 'grant_type=authorization_code'
I'm expecting to get an access token when I make the post request, but I'm getting this error:
{
"error": "invalid_grant"
}
The grant is valid i.e not expired. Server time is in sync with machine time. Expiry time is 5 minutes but doesnt work even before it's expired.

Whatsapp API not actually sending media message

I am trying to send an image via the Whatsapp API, but failing. I have uploaded an image, have the media ID and can download it with curl. Even an image link doesn't work - I don't get any error, in fact the response looks totally fine! Here's what I tried;
Trying to send an image as uploaded media with ID
curl -X POST \
'https://graph.facebook.com/v15.0/XXX/messages' \
-H 'Authorization: Bearer XXX' \
-H 'Content-Type: application/json' \
-d '{
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": "XXX",
"type": "image",
"image": {"id" : "XXX"}
}'
# response:
# {"messaging_product":"whatsapp","contacts":[{"input":"XXX","wa_id":"XXX"}],"messages":[{"id":"wamid.XXX"}]}
Trying to send an image as a link
curl -X POST 'https://graph.facebook.com/v13.0/SENDER/messages' \
-H 'Authorization: Bearer XXX' \
-H 'Content-Type: application/json' \
-d '{
"messaging_product": "whatsapp",
"recipient_type": "individual",
"to": "XXX",
"type": "image",
"image": { "link" : "https://placekitten.com/500/500" }
}'
# response:
# {"messaging_product":"whatsapp","contacts":[{"input":"XXX","wa_id":"XXX"}],"messages":[{"id":"wamid.XXX}]}
Both seem OK, but I don't actually receive anything. When I send with a message template, that works fine immediately.
Well, two days later my request started to both suddenly work without me changing anything. It seems my account or project or something might have been in some kind of verification cycle that didn't allow sending media.

"Invalid param: not a Token account" when trying to obtain the balance of USDT account in Solana

I'm trying to get the balance of a random USDT account in Solana. I've tried several public gateways and hasn't successed. Here's one example:
curl --request POST \
--url https://solana-mainnet.g.alchemy.com/v2/demo \
--header 'accept: application/json' \
--header 'content-type: application/json' \
--data '
{
"id": 1,
"jsonrpc": "2.0",
"method": "getTokenAccountBalance",
"params": [
"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA"
]
}
'
===>
{"jsonrpc":"2.0","error":{"code":-32602,"message":"Invalid param: not a Token account"},"id":1}
Why is it "not a token account"? What's the matter?
Here's an account - https://solscan.io/account/TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA
update 1
this address won't work either, resulting in the same error:
5Xm6nU1Bi6UewCrhJQFk1CAV97ZJaRiFw4tFNhUbXy3u
TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA is the Token Program itself and not a token account. This is a token account:
https://solscan.io/account/2SYZWm9WeCXb7LBX7dqXgk1dfF5Xa7wJobDSLos8urXp

WSO2 Identity Server 6.0 unable to find API for retrieve and update challenge questions

1.We are adding the security questions in /_system/config/repository/components/org.wso2.carbon.identity.mgt/questionCollection. We are trying to retrieve those using /me/challenges GET method under Challenge Questions API https://is.docs.wso2.com/en/latest/apis/challenge-rest-api/#/, but we are not able to retrieve them and also update them using GET and PUT API's. Is there any way to retrieve these questions which are added under this directory/_system/config/repository/components/org.wso2.carbon.identity.mgt/questionCollection and also update them??
As per the description, seems you want to manage the question sets and their questions stored in the server.
Use the following REST APIs to retrieve the question sets stored in /_system/config/identity/questionCollection location and update those question sets.
https://github.com/wso2/identity-api-server/blob/master/components/org.wso2.carbon.identity.api.server.challenge/org.wso2.carbon.identity.rest.api.server.challenge.v1/src/main/resources/challenge.yaml
GET challenge questions grouped by question set id:
curl --location --request GET 'https://localhost:9443/api/server/v1/challenges' \
--header 'Accept: application/json' \
--header 'Authorization: Basic YWRtaW46YWRtaW4='
Update questions in one set:
eg: PUT request to replace all questions in challengeQuestion2 set
curl --location --request PUT 'https://localhost:9443/api/server/v1/challenges/challengeQuestion2' \
--header 'Content-Type: application/json' \
--header 'Accept: */*' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--data-raw '[
{
"locale": "en_US",
"question": "Name of the hospital where you were born ?",
"questionId": "question2"
},
{
"locale": "en_US",
"question": "Model of your first car ?",
"questionId": "question1"
}
]'
eg: PATCH request to ADD one question to challengeQuestion2 set
curl --location --request PATCH 'https://localhost:9443/api/server/v1/challenges/challengeQuestion2' \
--header 'Content-Type: application/json' \
--header 'Accept: */*' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--data-raw '{
"operation": "ADD",
"challengeQuestion": {
"question": "what is your school",
"locale": "en_US",
"questionId": "question9"
}
}'
https://is.docs.wso2.com/en/latest/apis/challenge-rest-api/#/ this REST API is used to manage the challenge questions answers. /me/challenges and /{user-id}/challenges APIs are there to list out what are the available questions for the user to answer.

403 Error while creating API through Publisher API in Wso2

i am getting 403 forbideen error for below curl command,
Step1: Get the token
{
"access_token": "*********************c",
"scope": "am_application_scope apim:api_create apim:api_view",
"token_type": "Bearer",
"expires_in": 3600
}
Step 2:
curl --location --request POST 'https://PublisherDNS/api/am/publisher/v1/apis' \
--header 'Authorization: Bearer *************************' \
--header 'Content-Type: application/json' \
--header 'Cookie: JSESSIONID=508DADCDB2B1F4CF8C0E459C838AE10C; requestedURI=../../api/am/publisher/v1/apis' \
--data-raw '{
"name": "PizzaShackAPI",
"description": "This is a simple API for Pizza Shack online pizza delivery store.",
"context": "pizza",
"version": "1.0.0",
} ```
Can you try with v1.0 instead of v1 in your URL? (Also, v0.15 should be working as well)