Page not found error in Django and rest framework - django-rest-framework

Working on a payment gateway integration where I need to save some values like transaction details. I am getting problem with url.
The following url which I am using to save the and to redirect to success page :
urlpatterns = [
path('api/payment_details/<int:pk>/',payment_details,name="payment_details")
]
so the url I want is http://127.0.0.1:8000/basic/api/payment_details/id=6&response=success/
but I am getting http://127.0.0.1:8000/basic/api/payment_details/id%3D6&response%3Dsuccess/
response =success we get after transaction has done successfully

Related

Laravel 9 to home page redirected

I'm starting in Laravel, and I'm using Laravel 9, I'm making an API, starting for a User CRUD, when I register the user, everything it's ok, but when I got some error, example if I try to register the same email or wrong login data, the API show me the home Laravelpage, instead of to show me some error at JSON format
User registered succefully
User doesn't registered succefully
I'm trying to handle the error, I would like to get some JSON messages showing what's wrong or what happened
I have resolved the problem, I was using Postman, and you need to add at header Accept = application/json

Google Identity for server-side web app - redirect URI mismatch

I'm attempting to set up the Code Model for Google authentication, so that my user can oauth with Google and my app can retrieve their Calendar data. I'm stuck on step 5 here, where I'm supposed to exchange the authorization code for refresh and access tokens. I'm using nestjs in the backend and React in the frontend.
What I've done already that's working:
User clicks a button on my web app's page
Client sets up google.accounts.oauth2.initCodeClient with the /calendar scope, in ux_mode: popup
User is shown the Google popup and can auth thru that
Client receives a response from Google containing the authorization code
Client makes a POST call to my backend to send it just that authorization code
In step 5, the client makes the POST call to localhost:4000/auth/google-test. In the backend, I'm using the googleapis package and have:
export const oauth2Client = new google.auth.OAuth2(
process.env.GOOGLE_CLIENT_ID,
process.env.GOOGLE_CLIENT_SECRET,
'http://localhost:4000/' // <- note, I'm not sure if this is corect
);
And in the relevant controller route, I'm doing:
#Post('google-test')
public async googleTest(#Body() bodyReceived: any): Promise<any> {
let { code } = bodyReceived
let { tokens } = await oauth2Client.getToken(code)
oauth2Client.setCredentials(tokens);
console.log('Tokens: ' + tokens);
return
The error I'm getting is related to oauth2Client.getToken(code), and the error is a redirect_uri_mismatch. In GCP for the credentials for this app, I've added all of these as "Authorized redirect URIs":
http://localhost:3000/home
http://localhost:4000/auth/google-test
http://localhost:4000
What am I doing wrong?
It took a bit more Googling, but turns out that the right answer is to have my server make the token call with the redirect uri as "postmessage".
This SO question gives a bit more context. A somewhat unbelievable message, but it seems to work for my app.
It is evidently that what is happening is that the redirect URI does not match with the one in the GCP. This usually happens because backend tools such as Nestjs may be appending a trailing '/' to the URL and it may be interpreted as being part of the redirect_uri value.
You can try by temoving any trailing '/' via this following method oauthurl.replace(/\/$/, '')
Moreover, you can pass the generated auth URL to a meta tag. And check the html header to confirm what is the URL value.

how to get the logged in user data in nuxtjs?

I'm using laravel backend and nuxtjs frontend, when I send a login request I get a response includes the logged in user informations with a token, the response looks like this:
{"message":"success","token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIxIiwianRpIjoiNzFkYjA1MWM2MTYxMmE4YzAyNWI2YjU3N2xMzJiNzJjMjI0MzRlY2IzNzYwNTg2N2NjOWQ5ZWEwY2MiMJM3uYEiZ8GSlPlQhIctVErO2KzwXOBxifWWoM7et_qT-mgvfsk3ljwiQF9iPQw-WeekBx8J8lcmxDLESa3tfE1Re1Xk2flkcBLmiI4JN2YHh08U1U","user":{"id":1,"role_id":4587,"firstname":"Hans","lastname":"newman","email":"newman#gmail.com","email_verified_at":null,"phone":"89498","skype":"gdgdfg","birthdate":"2021-05-02","address":"asdfaf","postalcode":14984,"city":"jisf","country":"isfisf","status":"mfof","created_at":"2021-06-16T09:33:08.000000Z","updated_at":"2021-06-16T09:39:41.000000Z","image":"1623835988-carlsen.png","description":"sfdgg","geo_lat":5.5,"geo_lng":8.1}}
after logging in I want to redirect the user to his profile page where he can see his data, how can I get the logged in user data from this response.
You can get the user details on the profile page using this.$auth.user which is provided by the nuxt auth module. This returns an array so you can access the actual details of the user using this.$auth.user[0] e.g this.$auth.user[0].email or this.$auth.user[0].firstname etc.
Also if you are using the nuxt module, you can access it using this.$store.state.auth.user.
Check out the nuxt auth module documentation for more info here
presuming the variable which you are saving response data in is response. you can access the user data via response.user. for accessing any data inside user you can access them further like response.user.id.
Beautified version of your response data for easier read:
{
"message":"success",
"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJhdWQiOiIxIiwianRpIjoiNzFkYjA1MWM2MTYxMmE4YzAyNWI2YjU3N2xMzJiNzJjMjI0MzRlY2IzNzYwNTg2N2NjOWQ5ZWEwY2MiMJM3uYEiZ8GSlPlQhIctVErO2KzwXOBxifWWoM7et_qT-mgvfsk3ljwiQF9iPQw-WeekBx8J8lcmxDLESa3tfE1Re1Xk2flkcBLmiI4JN2YHh08U1U",
"user":{
"id":1,
"role_id":4587,
"firstname":"Hans",
"lastname":"newman",
"email":"newman#gmail.com",
"email_verified_at":null,
"phone":"89498",
"skype":"gdgdfg",
"birthdate":"2021-05-02",
"address":"asdfaf",
"postalcode":14984,
"city":"jisf",
"country":"isfisf",
"status":"mfof",
"created_at":"2021-06-16T09:33:08.000000Z",
"updated_at":"2021-06-16T09:39:41.000000Z",
"image":"1623835988-carlsen.png",
"description":"sfdgg",
"geo_lat":5.5,
"geo_lng":8.1
}
}
if you're redirecting the user, you have to save the response in store so you can use it in another page. unless you are using Auth/Nuxt which saves the data in $auth.

Django-allauth + reactjs+ linkedin login redirect uri issue + Not enough permissions to access: GET /me

I am using drf + ReactJs to do social login am able to integrate google login and facebook login using django allauth package , but when I tried to integrate linkedin login getting error :
invalid redirect uri
TO be more precise am getting this error
allauth.socialaccount.providers.oauth2.client.OAuth2Error: Error retrieving access token: b'{"error":"invalid_redirect_uri","error_description":"Unable to retrieve access token: appid/redirect uri/code verifier does not match authorization code. Or authorization code expired. Or external member binding exists"}
----few updates after tying out few fixes -----
Tried fetching the access token from backend and login the user using a seprate api it showed the redirect uri issue.
Tried directly calling the linkedin token url from postman and now I get Invalid request error.
First method worked after few tryouts but now getting incorrect value error.
Tried fetching code with scope as r_liteprofile but now getting 403 forbidden
{'serviceErrorCode': 100, 'message': 'Not enough permissions to access: GET /me', 'status': 403}
I tried changing url to backend and frontend both showing same error. Can anyone get me how to fix this issue ?
I am not sure what all additional details needed for sorting this out, Please let me know if any needed.
Finally able to find the solution
the issue was with the code generated from the sdk used to implement linkedin login in reactjs, which has only scope
r_emailaddress
r_liteprofile
Adding additional scope
w_member_social
And regarding redirect uri issue
we are suppose to use the same redirect uri in both frontend and backend
made things working , posting this here since it will help someone in future facing same problem.
thank you all

codeigniter rest api not working on liver server

I have a url:-
http://brokers4homes.esoftech.in/
I have created a web service and created a customer
$route['api/v1_0/usersignup'] = "api/user_api/usersignup"
I am hitting url:-
http://brokers4homes.esoftech.in/index.php?api/v1_0/usersignup
but it does not give me any json result instead it redirects me to home mage:-
This is my form:-
http://brokers4homes.esoftech.in/index.php/rest_server

Resources