How to integrate Superset with gcloud oAuth? - apache-superset

I am trying to integrate in gcloud oAuh2.0. This is the code snippet:
OAUTH_PROVIDERS = [
{
'name': 'google',
'whitelist': ['#gmail.com'],
'icon': 'fa-google',
'token_key': 'access_token',
'remote_app': {
'base_url': 'https://www.googleapis.com/oauth2/v2/',
'request_token_params': {
'scope': 'email profile'
},
'request_token_url': None,
'access_token_url': 'https://accounts.google.com/o/oauth2/token',
'authorize_url': 'https://accounts.google.com/o/oauth2/auth',
'consumer_key': 'myKeyID',
'consumer_secret': 'MySecret'
}
}
]
I am able to access the authorization page and successfully sign in as well, but after the signing it redirects me to the page which shows invalid login details (Even though Google has validated it).
Here's what I receive:
What possibly could be the error?

Solved the error, I was trying to register with a pre-registered email, sorry for the confusion!

Related

django-allauth Azure Ad Configurations

I'm tyring to setup django azure ad authentication using django-allauth but currently the documentations is not having proper documentation for setting up Azure ad.
I have client_id, secret and tenant_id with me. I have tried few configurations but it seems to be not working.
Config 1:
SOCIALACCOUNT_PROVIDERS = {
'azure': {
'APP': {
'client_id': 'client_id',
'secret': 'secret',
'key': ''
}
}
}
Config 2:
SOCIALACCOUNT_PROVIDERS = {
'azure': {
'APP': {
'client_id': 'client_id',
'secret': 'secret',
'key': '',
'tenant_id': '',
}
}
}
I have experimented few more configuration but its seems to be not working
https://django-allauth.readthedocs.io/en/latest/providers.html
As you say, the documentation is lacking on this integration. I was able to get Azure SSO working with the following configuration in settings for a single tenant app. First, make sure you have all of the following declared in INSTALLED APPS:
"allauth",
"allauth.account",
"allauth.socialaccount",
"allauth.socialaccount.providers.microsoft",
Note the absence of .azure as a provider. My tests revealed that using .microsoft as the provider worked with my registered single tenant applications in Azure AD, where .azure did not, and would throw an error upon sign in. You did specify whether your app is single or multi-tenant.
Secondly, declare your configuration as follows:
SOCIALACCOUNT_PROVIDERS = {
'microsoft': {
'tenant': secrets.AZURE_AD_TENANT_ID,
'client_id': secrets.AZURE_AD_CLIENT_ID,
}
}
secrets. is just my custom secret manager, the important part is the syntax and the IDs you pass. The 'tenant' here is not your subscription tenant ID, but the tenant ID that is displayed in the Overview blade of your registered application in Azure AD. The client_id is in the same Overview area, just above "Object ID" as of this writing. Note the absence of APP: {} above. This threw me at first too. I picked up a clue from this GitHub post.
Finally, to get this to work, you must create a "Social Application" record in django-allauth's admin panel inside the Django Admin. Give the app whatever name you want, and add both the 'Client ID' and the 'Application Secret' here from the Azure AD Registered Application.

how to load swagger UI, in before_request looking for token but token used in particular endpoint

#flask, swagger, before_request problem
in app.py one function is decorated with before_request and in this fuction
"""
token = request.args.get('token')
if not token:
return jsonify({
'status': 'error',
'message': 'Unauthorized.'
})
# Parse Token
token = base64.urlsafe_b64decode(token)
token = token.decode('utf-8')"""
suppose i have some endpoints like /api/employees when i want load swagger UI its unauthrize becauz of before request.
so i want to load ui, and afterthat in parameter token send to get response from endpoints
if you have simliar scenerio please share me support doc
In this case we have to bypass some URLs like '/apidocs', '/', and some HTML, css, jquery related config have to add in swagger config.
#app.before_request
def before_request():
if request.path == '/apidocs' or request.path == '/apispec.json':
return shutdown_session()
try:
# some code here
except:
# something here
in swagger config you have add like this
swagger_config = {
"headers": [
],
"specs": [
{
"endpoint": 'apispec',
"route": '/apispec.json',
"rule_filter": lambda rule: True, # all in
"model_filter": lambda tag: True, # all in
}
],
"static_url_path": "/flasgger_static",
"swagger_ui": True,
"specs_route": "/apidocs",
'swagger_ui_bundle_js': '//unpkg.com/swagger-ui-dist#3/swagger-ui-bundle.js',
'swagger_ui_standalone_preset_js': '//unpkg.com/swagger-ui-dist#3/swagger-ui-standalone-preset.js',
'jquery_js': '//unpkg.com/jquery#2.2.4/dist/jquery.min.js',
'swagger_ui_css': '//unpkg.com/swagger-ui-dist#3/swagger-ui.css'
}

Facebook Graph API get page_impressions

I've been using the graph api to get insights for our page. I log in, authorise and get a page access token. Recently, Facebook made it impossible to get any data without getting your app reviewed. I've managed to get my app reviewed with the following permissions:
manage_pages, email, read_insights, default:
These are found here: https://developers.facebook.com/docs/facebook-login/permissions/
This is my call:
https://graph.facebook.com/v3.0/me/insights/page_impressions_by_age_gender_unique
And this is the response:
{
"data": [
],
"paging": {
"previous":
"https://graph.facebook.com/v3.0/300196376675661/insights?access_token=xxx&pretty=0&metric=page_impressions_by_age_gender_unique&since=1532674800&until=1532847600",
"next": "https://graph.facebook.com/v3.0/300196376675661/insights?access_token=xxx&pretty=0&metric=page_impressions_by_age_gender_unique&since=1533020400&until=1533193200"
}
}
Are there additional permissions that I need to get in my app? Has anyone managed to get these insights?
Looking for these items:
[
("page_impressions_by_age_gender_unique", "day"),
("page_impressions", "day"), ("page_impressions_unique", "day"),
("page_impressions_paid", "day"),
("page_views_by_age_gender_logged_in_unique", "day")
]
This might help!
Your query should be like this =>
"<your_page_id>/insights?metric=page_impressions_by_age_gender_unique&accessToken=<your_page_access_token>"
Make sure to pass the Page Access Token, not user token.

DisallowedRedirect (Unsafe redirect to URL with protocol) Django

I am getting DisallowedRedirect error when i am logging user in
The two views are
def login(request):
c={}
c.update(csrf(request))
form=LoginForm()
errors=()
c['form']=form
c['errors']=errors
return render(request,'news/login.html',c)
def auth_view(request):
username=request.POST.get('username','')
password=request.POST.get('password','')
user=auth.authenticate(username=username,password=password)
if user is not None:
auth.login(request,user)
return HttpResponseRedirect('news:home',request)
else:
form=LoginForm()
errors=('Invalid Username or Password',)
return render(request,'news/login.html', {'form':form,'errors':errors})
instead of
return HttpResponseRedirect('news:home',request)
this:
return HttpResponseRedirect(reverse('news:home'))
or
return redirect('news:home')
or
return redirect(reverse('news:home'))
HttpResponseRedirect.allowed_schemes.append('news')
In addition to the current answers if you want to redirect to an custom scheme, you can use following code:
class CustomSchemeRedirect(HttpResponsePermanentRedirect):
allowed_schemes = ['tg']
def redirect(request):
return CustomSchemeRedirect('tg://resolve?domain=durov')
Make sure that when you get this error you have the correct scheme supplied in front of your URL. By default the django.http.HttpResponseRedirect does not allow redirects to URLs that don't start with one of the following schemes:
http
https
ftp
So if the URL you supply is, for example, localhost:8000 make sure you change it to http://localhost:8000 to get it to work.
Don't forget that apart from enabling the redirect, nowadays Safari won't open your redirected deep links unless you do the work outlined here: https://developer.apple.com/documentation/xcode/supporting-associated-domains
Add the url path into your Django app:
path('.well-known/apple-app-site-association', views.web.links.appleAppSiteAssociation, name='.well-known/apple-app-site-association'),
The view should return a JSON response:
def appleAppSiteAssociation(request_):
"""
Tell Apple that certain URL patterns can open the app
:param request_:
:return:
"""
json = {
"applinks": {
"details": [
{
"appIDs": ["MY.APP.BUNDLEID"],
"components": [
{
"#": "no_universal_links",
"exclude": True,
"comment": "Matches any URL whose fragment equals no_universal_links and instructs the system not to open it as a universal link"
},
{
"/": "/dataUrl=*",
"comment": "Matches any URL whose path starts with /dataUrl="
},
]
}
]
},
"webcredentials": {
"apps": ["MY.APP.BUNDLEID"]
},
}
return JsonResponse(json)
Add the webcredentials:MYPROTOCOL into the Associated Domains in XCode

Using Python facebook SDK for posting Open Graph action

Can I use the Facebook Python SDK to post a open graph action. As the python facebook SDK is now very old, how can I use that to post a open graph action - I could not find an example anywhere.
You can use the GraphAPI.request(self, path, args=None, post_args=None) function from the Python for Facebook 3rd party library (http://www.pythonforfacebook.com/). Just follow the documentation on the Facebook Developer Site to build the path, args and post_args needed to make the API call.
Using the facebook-sdk package from pip you can post an action with the put_object call
facebook.GraphAPI(token).put_object("me", "my_app:my_action", "my_object_type"="http://my_objects_url")
you can use https://github.com/zetahernandez/facebook-python-sdk
it supports doing simple request like
facebook = Facebook(
app_id='{app_id}',
app_secret='{app_secret}',
default_graph_version='v2.5',
)
facebook.set_default_access_token(access_token='{access_token}')
try:
response = facebook.get(endpoint='/me?fields=id,name')
except FacebookResponseException as e:
print e.message
else:
print 'User name: %(name)s' % {'name': response.json_body.get('id')}
or request in batch
facebook = Facebook(
app_id='{app_id}',
app_secret='{app_secret}',
)
facebook.set_default_access_token(access_token='{access_token}')
batch = {
'photo-one': facebook.request(
endpoint='/me/photos',
params={
'message': 'Foo photo.',
'source': facebook.file_to_upload('path/to/foo.jpg'),
},
),
'photo-two': facebook.request(
endpoint='/me/photos',
params={
'message': 'Bar photo.',
'source': facebook.file_to_upload('path/to/bar.jpg'),
},
),
'photo-three': facebook.request(
endpoint='/me/photos',
params={
'message': 'Other photo.',
'source': facebook.file_to_upload('path/to/other.jpg'),
},
)
}
try:
responses = facebook.send_batch_request(requests=batch)
except FacebookResponseException as e:
print e.message