I am trying to create a login using linkedIn and authlib, but I'm running into errors when I try and receive my token. I am able to redirect to the linked in authentication and then redirect to my callback. But im having issues with the authorized_access_token(request).
Can someone help check if my implementation is correct?
This is the error im recieving:
{"error":"invalid_request: A required parameter "client_secret" is missing"}
oauth.register(
"linkedin",
client_id=LINKEDIN_CLIENT_ID,
client_secret=LINKEDIN_CLIENT_SECRET,
api_base_url='https://api.linkedin.com/v2/',
authorize_url='https://www.linkedin.com/oauth/v2/authorization',
access_token_url='https://www.linkedin.com/oauth/v2/accessToken',
client_kwargs={'scope': 'openid profile email'},
)
@router.get('/login')
async def linkedin_login(request: Request):
linkedin = oauth.create_client('linkedin')
if linkedin:
print(linkedin.name)
redirect_uri = request.url_for('linkedin_auth')
print(redirect_uri)
return await linkedin.authorize_redirect(request, redirect_uri)
else:
return {'error': 'linkedin client not found'}
@router.get('/auth')
async def linkedin_auth(request: Request):
linkedin = oauth.create_client('linkedin')
if linkedin:
try:
token = await linkedin.authorize_access_token(request)
return token
except Exception as e:
return {'error': str(e)}
I have tried changing the registration configurations and that doesnt seem to help. I believe my implementation is correct, but I am still getting errors
The request passed in the
authorize_access_tokencall is missing theclient_secretto fetch the access token.I have assumed that you are developing with FastAPI framework.
Some improvements over your code:
.envfile.