KeyCloak Admin Functionality in Python - python

Am trying to access Keycloak Admin for getting the user information with following code. Am getting 403 error while executing any GET commands.Can anyone help or have seen this in error. Am getting 'None' when am priniting, print(keycloak_admin1.get_token()).
from keycloak import keycloak_admin
keycloak_admin1 = keycloak_admin.KeycloakAdmin(server_url=endpoint,username=username, password=password,realm_name=realmname,client_id= clientid,client_secret_key=clientsecret,verify= True)
print(keycloak_admin1.realm_name)
print(keycloak_admin1.token)
# User counter
count_users = keycloak_admin1.users_count()
getusers = keycloak_admin1.get_user()
print(count_users)

I ended up using Keycloak API's and it resolved my issue. Still not sure why python.keycloak package not working. So marking this issue done.

Related

Getting 401 Code when trying to Authenticate with Bitbucket Cloud API

Getting the issue below, I can get the repositories but when I try get the commit's, that is when it fails and I get a 401. Repo's and workspace are private so the first one would fail I imagine if there was an issue with the code entirely. Anyone done this recently?
baseUrlv2 = "https://bitbucket.org/api/2.0"
role = "contributor"
username = {bitbucket_username}
password = {bitbucket_app_password}
r = requests.get("{base}/repositories/{workspace}?role={role}".format(base=baseUrlv2, role=role),
auth=(use
rname, password))
repos = r.json()
while 'next' in repos:
for repo in repos["values"]:
commitLink = repo["links"]["commits"]["href"]
repoSlug = repo["slug"]
#the request below seems to be the issue :\
r = requests.post((commitLink), auth=(username,password))
c = r.json() #this is where it breaks
After a bunch of trial and error wherein the Atlassian documentation says use your Bitbucket username + App Password.. This wasn't the case.
You need to use your normal email and password to actually use the API.
Some strange issues in general with the API calls for Bitbucket but this issue is resolved.

GitHub "Requires Authentication" error when using PyGithub

I was trying to figure out how to use the PyGithub module, but I keep getting the same error:
github.GithubException.GithubException: 401 {"message": "Requires authentication", "documentation_url": "https://docs.github.com/rest/reference/users#get-the-authenticated-user"}
My code is pretty simple, considering I just started out:
from github import Github
g = Github("Charonum","xxxxxxxx")
user = g.get_user()
print(user.name)
print(user.login)
The error is when it gets to print(user.name).
Looking at their documentation, it doesn't look like you're initializing the Github class correctly. I would read through that to find more about how to properly setup. The error is pretty clear that you don't have your authentication credentials input properly.
Example from the documentation:
from github import Github
# using an access token
g = Github("access_token")
# Github Enterprise with custom hostname
g = Github(base_url="https://{hostname}/api/v3", login_or_token="access_token")

Creating Keycloak user from docker container

I am having problems creating users using the Keycloak REST API from my docker container running a Django application. The following works using postman:
Fetch admin token
Create user:
The following does NOT work in python, and returns 401 Unauthorized:
Fetch admin toke (This successfully returns a token):
Create user (This returns 401):
I am using the exact same user credentials in both scenarios,and since I am able to get this to work in postman I don't think there's any problem with access/roles etc.
Any help is greatly appreciated. Thanks!
You are not givingspace after "Bearer" so instead of "Bearer"+ token , use "Bearer " + token
you can also geenrate python code from postman :
click code:
Search for python
copy paste the generated code

Flask-OpenID Steam login 500 error

I am following this guide on how to sign in to Steam using Flask-OpenID: http://flask.pocoo.org/snippets/42/
The Flask app returns a 500 error when it encounters the following portion of code:
#app.route('/login')
#oid.loginhandler
def login():
if g.user is not None:
return redirect(oid.get_next_url())
return oid.try_login('http://steamcommunity.com/openid')
Specifically the following line:
return oid.try_login('http://steamcommunity.com/openid')
I know the guide is quite outdated (dated 02-17-2011). Is there an updated guide out there or is there a fix for this error? I can't seem to find it.
For reference: https://pythonhosted.org/Flask-OpenID/#flask_openid.OpenID.try_login
Tried the app in debug mode and got the following error:
RuntimeError: the session is unavailable because no secret key was set. Set the secret_key on the application to something unique and secret.
Did a bit of googling and came up with a solution for this: secret key not set in flask session
Ended up just adding the following line:
app.secret_key = "super secret key goes here"
This has fixed my 500 error issue; finally getting an actual redirect to the steam login page.

django-social-auth twitterBackend , always redirected to LOGIN_URL_ERROR

I started using django-social-auth which looks great, i want to setup a tiny twitter app and just need the twitter connect. I followed the guidelines and examples.
The twitter connect looks like it's working, i am redirected to twitter authentication but when returning back to my callbackUrl i get
always redirected to the LOGIN_URL_ERROR, i have no error messages. I tried adding django logging still no error is showed.
The messages module used in the example views gives me:
"Sorry but some error made you impossible to login. Please try again"
I am currently testing on localhost so maybe it's the problem, i have setup the twitter app with the url: local.dev:8000 and callbackUrl: local.dev:8000/filtered
with a mapping on /etc/hosts
settings.py
social_settings.py
views.py
urls.py
python2.7, django 1.3, django-social-auth github repo

Categories

Resources