Django Allauth, Twitter Scope - django

I'd like to get the user email from the twitter oauth. So I requested this in the app settings.
I added the scope (to settings.py):
SOCIALACCOUNT_PROVIDERS = {
'linkedin': {
'SCOPE': [
'r_emailaddress',
'r_basicprofile',
'r_fullprofile',
],
'PROFILE_FIELDS': [
'id',
'first-name',
'last-name',
'positions',
'email-address',
'picture-url',
'public-profile-url',
'headline',
'skills',
'summary',
'location',
'industry',
'positions',
'company',
'specialties',
'public-profile-url',
],
'LOCATION_FIELDS': [
'location',
],
'POSITION_FIELDS': [
'company',
]
},
'twitter': {
'SCOPE': ['email'],
},
}
However, I'm still having the user data like the name, picture ..etc but not the email.
Any suggestion ?

Related

How to remove intermediate pages during Django all auth Facebook login?

I am using Django all-auth to enable Google & Facebook social logins to my application. The flow is working fine but there are two unnecessary screens in the flow. The config is as follows:
ACCOUNT_ALLOW_REGISTRATION = env.bool("DJANGO_ACCOUNT_ALLOW_REGISTRATION", True)
ACCOUNT_AUTHENTICATION_METHOD = "email"
ACCOUNT_EMAIL_REQUIRED = True
ACCOUNT_USERNAME_REQUIRED = False
ACCOUNT_EMAIL_VERIFICATION = "none"
ACCOUNT_ADAPTER = "project.users.adapters.AccountAdapter"
SOCIALACCOUNT_ADAPTER = "project.users.adapters.SocialAccountAdapter"
SOCIALACCOUNT_PROVIDERS = {
"google": {
"SCOPE": [
"profile",
"email",
"https://www.googleapis.com/auth/youtube",
"https://www.googleapis.com/auth/youtube.readonly",
"https://www.googleapis.com/auth/youtube.upload",
"https://www.googleapis.com/auth/youtube.force-ssl",
],
"AUTH_PARAMS": {
"access_type": "offline",
},
},
"facebook":
{
'METHOD': 'oauth2',
'SCOPE': ['email', 'public_profile'],
'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
'INIT_PARAMS': {'cookie': True},
'FIELDS': [
'id',
'first_name',
'last_name',
'middle_name',
'name',
'name_format',
'picture',
'short_name'
],
'EXCHANGE_TOKEN': True,
'LOCALE_FUNC': lambda request: 'en_US',
'VERIFIED_EMAIL': False,
'VERSION': 'v7.0',
},
}
This is what I see after clicking on Google/Facebook login button:
And this comes up after completing Facebook login:
I don't want any of these two intermediate screens, and tried modifying configuration as well. But these screens are not mentioned in the Django All-Auth docs so what am I missing?
The docs don't recommend using SOCIALACCOUNT_LOGIN_ON_GET = True for security reasons. Use a form instead to send a POST request:
<form action="{% provider_login_url 'facebook' %}" method="post">
{% csrf_token %}
<button type="submit">Continue with Facebook</button>
</form>
You also need to set SOCIALACCOUNT_AUTO_SIGNUP = True in settings.py (this is the default value).
Try setting SOCIALACCOUNT_LOGIN_ON_GET to TRUE.
https://django-allauth.readthedocs.io/en/latest/release-notes.html#backwards-incompatible-changes-1
Open your setting.py file of django project
and add following line in bottom of the file
SOCIALACCOUNT_LOGIN_ON_GET = True

How to get user's phone number from python social auth(google-oauth2)

I use python social auth and django rest framework.
I want to fetch the user phone number.
Settings
SOCIAL_AUTH_GOOGLE_OAUTH2_KEY = config('GOOGLE_ID')
SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET = config('GOOGLE_SECRET')
SOCIAL_AUTH_RAISE_EXCEPTIONS = False
SOCIAL_AUTH_USER_MODEL = 'users.TransUser'
SOCIAL_AUTH_GOOGLE_OAUTH2_USER_FIELDS = ['email', 'firstname', 'lastname', 'phone_number']
SOCIAL_AUTH_GOOGLE_OAUTH2_SCOPE = [
'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/userinfo.profile',
'https://www.googleapis.com/auth/user.phonenumbers.read',
'profile',
'email',
]
Ouput
{'access_token': 'xxxxxxxx',
'email': 'xxxxxxxx,
'email_verified': True,
'expires_in': 3582,
'family_name': 'xxxxxxx',
'given_name': 'xxxxx',
'id_token': 'xxxxxx',
'locale': 'es',
'name': 'xxxxxxx',
'picture': 'xxxxx',
'scope': 'https://www.googleapis.com/auth/userinfo.email '
'https://www.googleapis.com/auth/user.phonenumbers.read '
'https://www.googleapis.com/auth/userinfo.profile openid',
'sub': 'xxxxxx',
'token_type': 'Bearer'}
but never phone number.
I use user's phone number to registration it.
I activated people APi in google console.
Thx you

"The provided key element does not match the schema" when writing into a table in DynamoDB

I followed these aws documents in order to set up my DynamoDB table:
creating table
loading the data into the table
Initially I created the table without any concern and the table structure would look like this:
Name > String
(Primary Key)
Category > String
Threads > Number
Messages > Number
Views > Number
When I tried to load the data, which was given on the 2nd hyperlink above, it throws up an exception saying:
An error occurred (ValidationException) when calling the
BatchWriteItem operation: The provided key element does not match the
schema
I did use the following command via the aws cli:
aws dynamodb batch-write-item --request-items file:///home/kula/Documents/aws/sampledata/Forum.json
This is the json file I'm trying to load, which I copied it from aws.
I also had a look into this ticket, and removed the quotes for numbers but still did not have any luck. Where am I going wrong?
Any help would be appreciated.
I apparently ended up creating python scripts to create table and load data into it.
Creating table:
import boto3
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
table = dynamodb.create_table(
TableName='users',
KeySchema=[
{
'AttributeName': 'username',
'KeyType': 'HASH'
},
{
'AttributeName': 'last_name',
'KeyType': 'RANGE'
}
],
AttributeDefinitions=[
{
'AttributeName': 'username',
'AttributeType': 'S'
},
{
'AttributeName': 'last_name',
'AttributeType': 'S'
},
],
ProvisionedThroughput={
'ReadCapacityUnits': 1,
'WriteCapacityUnits': 1
}
)
# Wait until the table exists.
table.meta.client.get_waiter('table_exists').wait(TableName='users')
Loading data into the table:
#!/usr/bin/python
import boto3
dynamodb = boto3.resource('dynamodb', region_name='us-east-1')
table = dynamodb.Table('users')
with table.batch_writer() as batch:
batch.put_item(
Item={
'account_type': 'standard_user',
'username': 'johndoe',
'first_name': 'John',
'last_name': 'Doe',
'age': 25,
'address': {
'road': '1 Jefferson Street',
'city': 'Los Angeles',
'state': 'CA',
'zipcode': 90001
}
}
)
batch.put_item(
Item={
'account_type': 'standard_user',
'username': 'bobsmith',
'first_name': 'Bob',
'last_name': 'Smith',
'age': 18,
'address': {
'road': '3 Madison Lane',
'city': 'Louisville',
'state': 'KY',
'zipcode': 40213
}
}
)
batch.put_item(
Item={
'account_type': 'super_user',
'username': 'alicedoe',
'first_name': 'Alice',
'last_name': 'Doe',
'age': 27,
'address': {
'road': '1 Jefferson Street',
'city': 'Los Angeles',
'state': 'CA',
'zipcode': 90001
}
}
)
print(table.creation_date_time)
Hope this helps someone!
I ran into a similar issue when trying to batch insert via aws dynamodb batch-write-item --request-items file://data/sample_services_data.json
It turns out that your primary partition key is case sensitive. In this scenario below, '77' will fail the import. If you change it to 'id' instead of 'Id' it will import without throwing the schema error.
{
"PutRequest": {
"Item": {
"Id": { "S": "77" },
"name": {"S":"Amazon Web Services"},
"language": {"S":"Python"},
"description": {"S":"Awesome super service"}
}
}
},
{
"PutRequest": {
"Item": {
"id": {"S":"99"},
"name": {"S":"Epic Service"},
"language": {"S":"NodeJS"},
"description": {"S":"Awesome epic service"}
}
}
}

Django-Allauth Scopes not working on any providers

I have added scopes to each provider but I do not receive all the additional data in extra_data. I only receive the default extra data. When using oauth facebook does ask to I will allow the data to be used but I do not recieve the data such as user_likes, user_activites. Same with google, and instagram. The spotify provider is a custom provider.
SOCIALACCOUNT_PROVIDERS = \
{
'facebook':
{'SCOPE': ['email', 'public_profile', 'user_activities', 'user_likes',
'user_interests', 'publish_stream', 'user_friends'],
'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
'METHOD': 'js_sdk'},
'google':
{'SCOPE': ['https://www.googleapis.com/auth/userinfo.profile', 'https://www.googleapis.com/auth/userinfo.email',
'https://www.googleapis.com/auth/youtube.readonly']
, 'AUTH_PARAMS': {}},
'instagram':
{'SCOPE': ['basic']
, 'AUTH_PARAMS': {}},
'spotify':
{'SCOPE': ['playlist-modify-public', 'user-follow-read', 'user-read-email']
, 'AUTH_PARAMS': {}},
}
This is probably a bit too late, but I had the same problem fetching additional data from Facebook using django-allauth.
The solution was to simply list the fields you want.
SOCIALACCOUNT_PROVIDERS = \
{
'facebook':
{'SCOPE': ['email', 'public_profile', 'user_activities', 'user_likes','user_interests', 'publish_stream', 'user_friends'],
'AUTH_PARAMS': {'auth_type': 'reauthenticate'},
'METHOD': 'js_sdk',
'FIELDS': [
'id',
'email',
'name',
'first_name',
'last_name',
'likes', #This is the one you want
'friends',
# user_interests is deprecated
],},
# other providers
}
The same probably applies to all the others too. I cannot say as I haven't used any others yet.

Django and Extjs, how to use combo with jsonstore

I want to display an extjs combo with a JsonStore
Server side I use python/Django.
So, this is my combo:
xtype: 'combo',
store: new Ext.data.JsonStore({
url: 'get_peoples',
root: 'data',
totalProperty: 'total',
fields: [
{name: 'name', mapping: 'fields.name'},
{name: 'subname', mapping: 'fields.subname'}
],
autoLoad: true
}),
trigerAction: 'all'
and the views.py server side:
def get_peoples(request):
queryset = People.objects.all()
data = '{"total": %s, "%s": %s}' % \
(queryset.count(), 'data', serializers.serialize('json', queryset))
return HttpResponse(data, mimetype='application/json')
the get_people call give me
{"total": 1, "data": [{"pk": 1, "model": "myapp.people", "fields": {"name": "Paul", "subname": "Di Anno"}}
I think i'm not doing it right, cause my combo doesn't display any item
You need to add displayField and valueField declarations to your ComboBox so that it knows which fields from your store to use for either role. Also, setting autoLoad in the store is not necessary.
new Ext.form.ComboBox({
xtype: 'combo',
store: new Ext.data.JsonStore({
url: 'get_peoples',
root: 'data',
totalProperty: 'total',
fields: [
{name: 'name', mapping: 'fields.name'},
{name: 'subname', mapping: 'fields.subname'}
]
}),
triggerAction: 'all',
// Just guessing at the proper fields here.
// Set them to whatever you wish.
displayField: 'name',
valueField: 'subname'
});