Laravel 8 Socialite check login - laravel

is there a way to check if the user has logged in with a Socialite?
because i want to create a post based on this authentication.
what i have done
if (!empty(Socialite::driver('linkedin')->stateless()->user()))
{
$linkedinuser = Socialite::driver('linkedin')->stateless()->user();
dd($linkedinuser);
}
return redirect('/profile/');
i expect to get the dump if user has authenticated with linkedin, or else return profile. Instead, i get an error
GuzzleHttp\Exception\ClientException
Client error: `POST https://www.linkedin.com/oauth/v2/accessToken` resulted in a `400 Bad Request` response: {"error":"invalid_request","error_description":"A required parameter \"code\" is missing"}
how can this be checked ? thanks.

Related

how to retrieve the same error response received by webclient in spring reactive

I reveive a request from client, and to process that I have to make request to azure resource management app.
Now, if the client passes me incorrect info, and if I make direct call from postman to azure API, it returns me very useful info. refer below (below call contains incorrect query params) :
i get response like below in case of incorrect param passed :
{
"error": {
"code": "ResourceNotFound",
"message": "The Resource 'Microsoft.MachineLearningServices/workspaces/workspace_XYZ/onlineEndpoints/Endpoint_XYZ' under resource group 'resourceGroupXYZ' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix"
}
}
Now, I make this query using springboot reactive webclient API.
But I am not sure how to pass the same error back as it contains very useful info. The exception handling methods calls like onErrorReturn etc did not help me here to get the original error msg. :
response = getWebClient()
.post()
.uri(apiUrl)
.headers(h -> authToken)
.retrieve()
.bodyToMono(String.class)
// .onErrorReturn(response)
.block();

Login, Register problem in laravel 8 Cpanel

The route is https://test.iqbal.live/api/auth/login/
field: username , password
enter image description here
In local environment its fine, when i upload it cpanel give the error below:
{
"message": "The GET method is not supported for this route. Supported methods: POST.",
"exception": "Symfony\\Component\\HttpKernel\\Exception\\MethodNotAllowedHttpException",
}
Try with postman ... its working...

Forbidden: Bot was blocked by the user - laravel irazasyed/telegram-bot-sdk

Recently I get a lot of this exception:
[2020-07-21 00:00:51] local.ERROR: Forbidden: bot was blocked by the user {"exception":"[object] (Telegram\\Bot\\Exceptions\\TelegramResponseException(code: 403): Forbidden: bot was blocked by the user at /home/birjande/public_html/tel.birjandelectronic.shop/packages/irazasyed/telegram-bot-sdk/src/Exceptions/TelegramResponseException.php:58)
in my case when a user block the botm my bot fails in a infinite loop and send a message again and again and !
I got was this kind or error, Just times 10000!
in fact if I got a error it's repeat over 1000 times !
i use laravel 6 and irazasyed/telegram-bot-sdk
i create my own sendMessage like this
public function sendMessage($arr) {
try {
Telegram::sendMessage($arr);
} catch (TelegramResponseException $e) {
return "user has been blocked!";
}
}

Cognito throws ErrCodeNotAuthorizedException when user is already confirmed

Why does cognito throw ErrCodeNotAuthorizedException "NotAuthorizedException" when the status of the user is already confirmed when making a request to cognito to confirm the user.
The documentation specifies that ErrCodeNotAuthorizedException is thrown when a user is not authorized.
https://docs.aws.amazon.com/sdk-for-go/api/service/cognitoidentityprovider/#CognitoIdentityProvider.ConfirmSignUp
How should we handle this case? As it would be unclear if we made a request with invalid client secret as it would throw the same error.
Since the code is the same for the unauthorized case and user already confirmed case, the only possible way to differentiate the cases is to match the awsErr.Message() which provides the clear description of the error.
if awsErr, ok := err.(awserr.Error); ok {
switch awsErr.Code() {
case cognitoidentityprovider.ErrCodeNotAuthorizedException:
if awsErr.Message() == "User cannot be confirm. Current status is CONFIRMED" {
log.Println("Handle user already confirmed")
} else {
log.Println("Handle not authorized case")
}
...
default:
}
}

Google Docs Api v2 Invalid grant error with Malformed Auth Code description

I've just installed the Google API 2.0, setup my application and I'm trying to authorize a user but I keep getting this error:
array(2) {
["error"]=>
string(13) "invalid_grant"
["error_description"]=>
string(20) "Malformed auth code."
}
for creating the authorization link I use the function $oGoogleClient->createAuthUrl(); within \Google_Client
it takes me to the authorization page and then returns to my authorization page with a code in the url like this:
http://example.com/authorize/?code=4/AABBv8nQ5N4mqrOTANDphl_L4ROPnzK6yckffDu-dnlIJGE9ZOcXo9eehUVbzbExbMuhCZQAb5zu9_BIS-VI4E4#
To handle this request I use the api funcion $oGoogleClient->fetchAccessTokenWithAuthCode($sCode); found in \Google_Client
At first I thought it was because of the # at the end of the code, because PHP only gets the code paramete until before that hashtag, so I hardcoded it to test, but the result is the same error message of Malformed Auth Code.
Any idea on how to solve this?
Update: I've moved the code to a different server, and it will authorize correctly the code and retrieve the Access Token. I guess it should be something within the server, but I can't figure out what!
I am using Node.js googleapis client library, Here is my case:
The authorization code in the url hash fragment is be encoded by encodeURIComponent api, so if you pass this code to request access token. It will throw an error:
{ "error": "invalid_grant", "error_description": "Malformed auth code." }
So I use decodeURIComponent to decode the authorization code.
decodeURIComponent('4%2F_QCXwy-PG5Ub_JTiL7ULaCVb6K-Jsv45c7TPqPsG2-sCPYMTseEtqHWcU_ynqWQJB3Vuw5Ad1etoWqNPBaGvGHY')
After decode, the authorization code is:
"4/_QCXwy-PG5Ub_JTiL7ULaCVb6K-Jsv45c7TPqPsG2-sCPYMTseEtqHWcU_ynqWQJB3Vuw5Ad1etoWqNPBaGvGHY"
Generally the URL is Encoded, So decode the URL and try again
Try URL Encode/Decode Tool click here
In python it can be done as below:
import requests
from urllib.parse import unquote
# Decode the url
query_str = unquote(request.META.get('QUERY_STRING'))
# Or just decode CODE
code = unquote(code)
data_dict = {
"code": code, "redirect_uri":"", "grant_type": "authorization_code",
"client_id": "","client_secret": ""
}
resp = requests.post('https://oauth2.googleapis.com/token', data_dict)

Resources