bug fixand refactored code in the function to add scopes in the authorization url