jhuapl-boss / boss-oidc

Django Auth plugin specific to the Boss SSO Server
Apache License 2.0
13 stars 22 forks source link

Internal Server Error: /openid/callback/login/ #3

Closed Allan-Nava closed 6 years ago

Allan-Nava commented 6 years ago

I have got this error:

Internal Server Error: /openid/callback/login/
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
    response = self._get_response(request)
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.5/dist-packages/djangooidc/views.py", line 91, in authz_cb
    login(request, user)
  File "/usr/local/lib/python3.5/dist-packages/django/contrib/auth/__init__.py", line 139, in login
    request.session.cycle_key()
  File "/usr/local/lib/python3.5/dist-packages/django/contrib/sessions/backends/base.py", line 311, in cycle_key
    self.create()
  File "/usr/local/lib/python3.5/dist-packages/django/contrib/sessions/backends/db.py", line 54, in create
    self.save(must_create=True)
  File "/usr/local/lib/python3.5/dist-packages/django/contrib/sessions/backends/db.py", line 83, in save
    obj = self.create_model_instance(data)
  File "/usr/local/lib/python3.5/dist-packages/django/contrib/sessions/backends/db.py", line 69, in create_model_instance
    session_data=self.encode(data),
  File "/usr/local/lib/python3.5/dist-packages/django/contrib/sessions/backends/base.py", line 98, in encode
    serialized = self.serializer().dumps(session_dict)
  File "/usr/local/lib/python3.5/dist-packages/django/core/signing.py", line 93, in dumps
    return json.dumps(obj, separators=(',', ':')).encode('latin-1')
  File "/usr/lib/python3.5/json/__init__.py", line 237, in dumps
    **kw).encode(obj)
  File "/usr/lib/python3.5/json/encoder.py", line 198, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.5/json/encoder.py", line 256, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.5/json/encoder.py", line 179, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <oic.oic.message.AddressClaim object at 0x7fe8c7626cc0> is not JSON serializable
ERROR:django.request:Internal Server Error: /openid/callback/login/
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/exception.py", line 41, in inner
    response = get_response(request)
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 249, in _legacy_get_response
    response = self._get_response(request)
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 187, in _get_response
    response = self.process_exception_by_middleware(e, request)
  File "/usr/local/lib/python3.5/dist-packages/django/core/handlers/base.py", line 185, in _get_response
    response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/lib/python3.5/dist-packages/djangooidc/views.py", line 91, in authz_cb
    login(request, user)
  File "/usr/local/lib/python3.5/dist-packages/django/contrib/auth/__init__.py", line 139, in login
    request.session.cycle_key()
  File "/usr/local/lib/python3.5/dist-packages/django/contrib/sessions/backends/base.py", line 311, in cycle_key
    self.create()
  File "/usr/local/lib/python3.5/dist-packages/django/contrib/sessions/backends/db.py", line 54, in create
    self.save(must_create=True)
  File "/usr/local/lib/python3.5/dist-packages/django/contrib/sessions/backends/db.py", line 83, in save
    obj = self.create_model_instance(data)
  File "/usr/local/lib/python3.5/dist-packages/django/contrib/sessions/backends/db.py", line 69, in create_model_instance
    session_data=self.encode(data),
  File "/usr/local/lib/python3.5/dist-packages/django/contrib/sessions/backends/base.py", line 98, in encode
    serialized = self.serializer().dumps(session_dict)
  File "/usr/local/lib/python3.5/dist-packages/django/core/signing.py", line 93, in dumps
    return json.dumps(obj, separators=(',', ':')).encode('latin-1')
  File "/usr/lib/python3.5/json/__init__.py", line 237, in dumps
    **kw).encode(obj)
  File "/usr/lib/python3.5/json/encoder.py", line 198, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.5/json/encoder.py", line 256, in iterencode
    return _iterencode(o, 0)
  File "/usr/lib/python3.5/json/encoder.py", line 179, in default
    raise TypeError(repr(o) + " is not JSON serializable")
TypeError: <oic.oic.message.AddressClaim object at 0x7fe8c7626cc0> is not JSON serializable
[04/Dec/2017 08:43:12] "GET /openid/callback/login/?state=TeCCDOSWCHOUVWRA&code=PwLo-eO_5rJMWkaO9y0PzQjuH5DNACuRvXvWcxPV2t4.ef76031f-094c-4e55-b8e1-f217522b4ecc HTTP/1.1" 500 156069
derek-pryor commented 6 years ago

This seems to be related to the django-oidc plugin. Are you using the jhuapl-boss/django-oidc version of the plugin?

What version of Django are you running?

Allan-Nava commented 6 years ago

The problem is mapper, what can I do? If i need more data for auth user standard?

2017-12-04 19:49 GMT+01:00 Derek Pryor notifications@github.com:

This seems to be related to the django-oidc plugin. Are you using the jhuapl-boss/django-oidc version of the plugin?

What version of Django are you running?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jhuapl-boss/boss-oidc/issues/3#issuecomment-349064661, or mute the thread https://github.com/notifications/unsubscribe-auth/AVdMgxKXYf5KzAQjstDq5b8s4hw8kLRCks5s9D7SgaJpZM4Q0TQK .

derek-pryor commented 6 years ago

The problem is mapper? I don't understand.

Without more details about your Python/Django configuration I am unable to help.

On Mon, Dec 4, 2017 at 11:11 AM, Allan Nava notifications@github.com wrote:

The problem is mapper, what can I do? If i need more data for auth user standard?

2017-12-04 19:49 GMT+01:00 Derek Pryor notifications@github.com:

This seems to be related to the django-oidc plugin. Are you using the jhuapl-boss/django-oidc version of the plugin?

What version of Django are you running?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jhuapl-boss/boss-oidc/issues/3# issuecomment-349064661, or mute the thread https://github.com/notifications/unsubscribe-auth/ AVdMgxKXYf5KzAQjstDq5b8s4hw8kLRCks5s9D7SgaJpZM4Q0TQK .

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jhuapl-boss/boss-oidc/issues/3#issuecomment-349072353, or mute the thread https://github.com/notifications/unsubscribe-auth/AO6WU8VC-ghVuPDrvWWW0tFeUSvfp_tRks5s9EP1gaJpZM4Q0TQK .

Allan-Nava commented 6 years ago

I this is my settings.py


ALLOWED_HOSTS = ['*']

# Application definition

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.humanize',
    'jet.dashboard',
    'jet',
    'django.contrib.admin',
    'django.contrib.admindocs',
   # 'django.contrib.auth',
   # 'django.contrib.contenttypes',
   # 'django.contrib.sessions',
#    'django.contrib.sites',
   # 'django.contrib.messages',
    #'django.contrib.staticfiles',
 #   'django.contrib.flatpages',
    'bootcamp.allejo',
    'bossoidc',
    'djangooidc',
#    'djangocms_oscar',
    'bootstrap3',
#    'groups_manager',
    'guardian',
    'bootcamp.groups_manager',
    'bootcamp.activities',
    'bootcamp.articles',
    'bootcamp.authentication',
    'bootcamp.core',
    'bootcamp.feeds',
    'bootcamp.messenger',
    'bootcamp.questions',
    'bootcamp.search',
    'rest_framework',
    'rest_framework_swagger',
    'taggit',
)

AUTHENTICATION_BACKENDS = (
    'django.contrib.auth.backends.ModelBackend',
    'bossoidc.backend.OpenIdConnectBackend',
    'guardian.backends.ObjectPermissionBackend',
)

MIDDLEWARE_CLASSES = (
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.middleware.locale.LocaleMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
)

ROOT_URLCONF = 'bootcamp.urls'

WSGI_APPLICATION = 'bootcamp.wsgi.application'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            PROJECT_DIR.child('templates'),
  #          OSCAR_MAIN_TEMPLATE_DIR
        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
   #             'django.template.context_processors.i18n',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
    #            'oscar.apps.search.context_processors.search_form',
     #           'oscar.apps.promotions.context_processors.promotions',
      #          'oscar.apps.checkout.context_processors.checkout',
       #         'oscar.apps.customer.notifications.context_processors.notifications',
        #        'oscar.core.context_processors.metadata',
          ],
            'debug': DEBUG
        },
    },
]

# Internationalization
# https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'en-us'
SITE_ID = 1
TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

LANGUAGES = (
    ('en', 'English'),
    ('pt-br', 'Portuguese'),
    ('es', 'Spanish')
)

LOCALE_PATHS = (PROJECT_DIR.child('locale'), )

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_ROOT = PROJECT_DIR.parent.child('staticfiles')
STATIC_URL = '/static/'

STATICFILES_DIRS = (
    PROJECT_DIR.child('static'),
)

MEDIA_ROOT = PROJECT_DIR.parent.child('media')
MEDIA_URL = '/media/'

LOGIN_URL = '/'
LOGIN_REDIRECT_URL = '/feeds/'

ALLOWED_SIGNUP_DOMAINS = ['*']

FILE_UPLOAD_TEMP_DIR = '/tmp/'
FILE_UPLOAD_PERMISSIONS = 0o644

TAGGIT_CASE_INSENSITIVE = True

auth_uri = "http://login.livereporter.com:8080/auth/realms/django"
client_id = "tascout-allan"
public_uri = "http://192.168.1.179:8080"

from bossoidc.settings import *
configure_oidc(auth_uri, client_id, public_uri)

Python 3.5 Django 1.1

derek-pryor commented 6 years ago

Django 1.1 or 1.11?

On Mon, Dec 4, 2017 at 11:41 AM, Allan Nava notifications@github.com wrote:

I this is my settings.py

ALLOWED_HOSTS = ['*']

Application definition

INSTALLED_APPS = ( 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django.contrib.humanize', 'jet.dashboard', 'jet', 'django.contrib.admin', 'django.contrib.admindocs',

'django.contrib.auth',

'django.contrib.contenttypes',

'django.contrib.sessions',

'django.contrib.sites',

'django.contrib.messages',

#'django.contrib.staticfiles',

'django.contrib.flatpages',

'bootcamp.allejo',
'bossoidc',
'djangooidc',

'djangocms_oscar',

'bootstrap3',

'groups_manager',

'guardian',
'bootcamp.groups_manager',
'bootcamp.activities',
'bootcamp.articles',
'bootcamp.authentication',
'bootcamp.core',
'bootcamp.feeds',
'bootcamp.messenger',
'bootcamp.questions',
'bootcamp.search',
'rest_framework',
'rest_framework_swagger',
'taggit',

)

AUTHENTICATION_BACKENDS = ( 'django.contrib.auth.backends.ModelBackend', 'bossoidc.backend.OpenIdConnectBackend', 'guardian.backends.ObjectPermissionBackend', )

MIDDLEWARE_CLASSES = ( 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.middleware.locale.LocaleMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', )

ROOT_URLCONF = 'bootcamp.urls'

WSGI_APPLICATION = 'bootcamp.wsgi.application'

TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ PROJECT_DIR.child('templates'),

OSCAR_MAIN_TEMPLATE_DIR

    ],
    'APP_DIRS': True,
    'OPTIONS': {
        'context_processors': [
            'django.template.context_processors.debug',
            'django.template.context_processors.request',

'django.template.context_processors.i18n',

            'django.contrib.auth.context_processors.auth',
            'django.contrib.messages.context_processors.messages',
#            'oscar.apps.search.context_processors.search_form',
 #           'oscar.apps.promotions.context_processors.promotions',
  #          'oscar.apps.checkout.context_processors.checkout',
   #         'oscar.apps.customer.notifications.context_processors.notifications',
    #        'oscar.core.context_processors.metadata',
      ],
        'debug': DEBUG
    },
},

]

Internationalization

https://docs.djangoproject.com/en/1.6/topics/i18n/

LANGUAGE_CODE = 'en-us' SITE_ID = 1 TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True

LANGUAGES = ( ('en', 'English'), ('pt-br', 'Portuguese'), ('es', 'Spanish') )

LOCALE_PATHS = (PROJECT_DIR.child('locale'), )

Static files (CSS, JavaScript, Images)

https://docs.djangoproject.com/en/1.6/howto/static-files/

STATIC_ROOT = PROJECT_DIR.parent.child('staticfiles') STATIC_URL = '/static/'

STATICFILES_DIRS = ( PROJECT_DIR.child('static'), )

MEDIA_ROOT = PROJECT_DIR.parent.child('media') MEDIA_URL = '/media/'

LOGIN_URL = '/' LOGIN_REDIRECT_URL = '/feeds/'

ALLOWED_SIGNUP_DOMAINS = ['*']

FILE_UPLOAD_TEMP_DIR = '/tmp/' FILE_UPLOAD_PERMISSIONS = 0o644

TAGGIT_CASE_INSENSITIVE = True

auth_uri = "http://login.livereporter.com:8080/auth/realms/django" client_id = "tascout-allan" public_uri = "http://192.168.1.179:8080"

from bossoidc.settings import * configure_oidc(auth_uri, client_id, public_uri)

Python 3.5 Django 1.1

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jhuapl-boss/boss-oidc/issues/3#issuecomment-349081657, or mute the thread https://github.com/notifications/unsubscribe-auth/AO6WU7DubJhljfjhKBRq45OzfQ5hzH8Eks5s9ErogaJpZM4Q0TQK .

Allan-Nava commented 6 years ago

@derek-pryor (1, 11, 5, 'final', 0) this is my version

derek-pryor commented 6 years ago

The basic problem is that an object that cannot be JSON serialized is being put into the Django session object. I don't know if this is being triggered by a newer version of Django or the Keyclock server's response.

You could try triggering the logging statement at https://github.com/jhuapl-boss/django-oidc/blob/master/djangooidc/oidc.py#L128 to see the OIDC response that is being put into the Django session.

If you don't have Django or Python logging already setup then you can place something like the following in your Django settings.py file.

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': { 'class':'logging.StreamHandler' }
    },
    'loggers': {
        'djangooidc.oidc': { 'level': 'DEBUG' }
    }
}
Allan-Nava commented 6 years ago

Where do I have write this snippet?

And I have another question: How can I create a new user for keycloak with requests python?

2017-12-09 15:21 GMT+01:00 Derek Pryor notifications@github.com:

The basic problem is that an object that cannot be JSON serialized is being put into the Django session object. I don't know if this is being triggered by a newer version of Django or the Keyclock server's response.

You could try triggering the logging statement at https://github.com/jhuapl-boss/django-oidc/blob/master/ djangooidc/oidc.py#L128 to see the OIDC response that is being put into the Django session.

If you don't have Django or Python logging already setup then you can place something like the following in your Django settings.py file.

LOGGING = { 'version': 1, 'disable_existing_loggers': False, 'handlers': { 'console': { 'class':'logging.StreamHandler' } }, 'loggers': { 'djangooidc.oidc': { 'level': 'DEBUG' } } }

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/jhuapl-boss/boss-oidc/issues/3#issuecomment-350472607, or mute the thread https://github.com/notifications/unsubscribe-auth/AVdMg0RD85d5b54vnTXl8nqa9Ok4FLnqks5s-pdlgaJpZM4Q0TQK .

derek-pryor commented 6 years ago

In your Django settings.py file. It will log the debug messages from the linked file to the console.

A quick Google search turned up http://www.keycloak.org/docs-api/3.0/rest-api/index.html#_users_resource . We just let users self register, so I've not used it myself.

Allan-Nava commented 6 years ago

Message deleted as it was not related to the issue -Derek

Allan-Nava commented 6 years ago

@derek-pryor Ok, but I have extended the auth_user with another model. So if add a new mapper it crash the django...

Sorry for my bad english

Allan-Nava commented 6 years ago

@derek-pryor How can I extend the scope? https://github.com/jhuapl-boss/boss-oidc/blob/master/bossoidc/settings.py#L26

derek-pryor commented 6 years ago

To extend the scope you will need to add something like the following to settings.py after the configure_oidc(auth_uri, client_id, public_uri) line

OIDC_PROVIDERS['KeyCloak']['behaviour']['scope'] = ['openid', 'profile', 'email']
Allan-Nava commented 6 years ago

@derek-pryor So I need to override the variable OIDC_PROVIDERS['KeyCloak']['behaviour']['scope'] = ['openid', 'profile', 'email'] with the custom mapper, but how the auth_user handle this new scopes?

derek-pryor commented 6 years ago

As long as you override the variable it will be picked up when you log in. Currently there is no good way to provide a custom function that overrides https://github.com/jhuapl-boss/boss-oidc/blob/master/bossoidc/backend.py#L45 that would allow you to update the user model with data from the ODIC token.

I'm going to open a new issue to track that and I'll have an update out in the next couple of days.

Allan-Nava commented 6 years ago

Ok, because if I add a custom mapper in keycloak i have the error, @derek-pryor

I extend the auth_user with auth_profile (model) to add new attributes.

What is the best method to implement the new scopes?

Thanks

derek-pryor commented 6 years ago

What is the Keycloak Client Mapper that you are creating? I was able to add a "User Address" mapping, add values to the user's profile, and see the results in Django without any errors.

derek-pryor commented 6 years ago

Just merged in an update that allows you to pass scope to configure_oidc() and define a user function to handle the new scope values (UPDATE_USER_DATA). Check the updated README for more details.

Allan-Nava commented 6 years ago

For example? How can I use the function update user data?

Il giorno 11 dic 2017, alle ore 20:45, Derek Pryor notifications@github.com ha scritto:

Just merged in an update that allows you to pass scope to configure_oidc() and define a user function to handle the new scope values (UPDATE_USER_DATA). Check the updated README for more details.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

derek-pryor commented 6 years ago

Simple example using made up names File: django/project/utils.py

def update_user_data(user_obj, token_dict):
    user_obj.foo = token_dict['foo']

File: django/project/settings.py

scope = ['openid', 'profile', ...]
UPDATE_USER_DATA = 'project.utils.update_user_data'
configure_oidc(..., scope)
Allan-Nava commented 6 years ago

Hi @derek-pryor ,

are you sure the method update_user_data(user_obj, token_dict) is used like this? UPDATE_USER_DATA = 'project.utils.update_user_data' Do I pass the user_obj and token like this project.utils.update_user_data()?

Thanks

derek-pryor commented 6 years ago

In settings.py the variable UPDATE_USER_DATA points to a function reference that will be called each time the user is logged into the system. The boss-oidc code will automatically call that function with the user object and JWT token.

Allan-Nava commented 6 years ago

Ok @derek-pryor , in file utils.py do I need to import things?

And in this example:

auth_uri = "http://localhost:8080/auth/realms/sample"
client_id = "webapp"
public_uri = "http://localhost:8000"
from bossoidc.settings import *
scope = ['openid', 'profile',]
configure_oidc(auth_uri, client_id, public_uri, scope)
#keycloak
#from keycloakexample.utils  mappersimport update_user_data
UPDATE_USER_DATA = 'keycloakexample.utils.update_user_data'
derek-pryor commented 6 years ago

You only need to import what you need for update_user_data

FYI, the file can be called anything you want, it doesn't have to be utils.py

Allan-Nava commented 6 years ago

Ok I did what you told me, but when I put scope in the configure_oidc, the compilator gave mi this error:

File"/Desktop/kcdj/lol/keycloakexample/keycloakexample/settings.py", line 86, in <module>
 configure_oidc(auth_uri, client_id, public_uri, scope)
TypeError: configure_oidc() takes 3 positional arguments but 4 were given

I don't understand why? I have two questions:

this is model:

class Profile(models.Model):
    user = models.OneToOneField(User)
Giovanni-94 commented 6 years ago

Hello @Allan-Nava , @derek-pryor
more and less I have the same problem... I don't understand how implement a customs mappers. So, one time I defined the "example" class utils.py, how pass my customs mappers in the scope?

derek-pryor commented 6 years ago

Did you update the boss-oidc code you are using, if so how did you do it?

I don't know anything about custom mappers.

On Fri, Dec 15, 2017 at 6:27 AM, Allan Nava notifications@github.com wrote:

Ok I did what you told me, but when I put scope in the configure_oidc, the compilator gave mi this error:

File"/Desktop/kcdj/lol/keycloakexample/keycloakexample/settings.py", line 86, in configure_oidc(auth_uri, client_id, public_uri, scope) TypeError: configure_oidc() takes 3 positional arguments but 4 were given

I don't understand why? I have two questions: - first: custum mappers must be extended or implemented

  • second: how pass they in my class Profile

this is models

class Profile(models.Model): user = models.OneToOneField(User)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jhuapl-boss/boss-oidc/issues/3#issuecomment-352018657, or mute the thread https://github.com/notifications/unsubscribe-auth/AO6WU54yZQJTAmG_bqEpeDvdf3YjSWC0ks5tAoHdgaJpZM4Q0TQK .

Allan-Nava commented 6 years ago

@derek-pryor I try to implement the custom method inside utils.py but doesn't work.

auth_uri = "http://localhost:8080/auth/realms/sample"
client_id = "webapp"
public_uri = "http://localhost:8000"

from bossoidc.settings import *
scope = ['openid', 'profile', 'email','number','data']
configure_oidc(auth_uri, client_id, public_uri, scope)

#keycloak
#from keycloakexample.utils  mappersimport update_user_data
UPDATE_USER_DATA = 'keycloakexample.utils.update_user_data'

If I add scope in configure oidc give me an error

Giovanni-94 commented 6 years ago

Hi @derek-pryor @Allan-Nava , I tried what you saied:


auth_uri = "http://localhost:8080/auth/realms/sample"
client_id = "webapp"
public_uri = "http://localhost:8000"

 #(Optional) A function used to process additional scope values in the token
 #It also provides a helpful hook for each time a user logs in
 #Function Args:
 #user (User object): The user that is logging in
 #token (dict): The JWT object used to lookup and create or update the user
UPDATE_USER_DATA = 'keycloakexample.utils.update_user_data'

 #(Optional) A function used to process a user's roles for the application
 #It also provides a helpful hook for each time a user logs in
 #Function Args:
 #user (User object): The user that is logging in
 #roles (list of string): List of the roles the user is currently assigned
 #LOAD_USER_ROLES = 'path.to.function'

 #NOTE: The following two rules are automatically applied to all user account during
 #the login process to allow bootstrapping admin / superuser accounts.
 #The user will be assigned Django staff permissions if they have a 'admin' or 'superuser' role in 
 #Keycloak
 #The user will be assigned Django superuser permissions if they have a 'superuser' role in Keycloak

 #auth_uri = "https://auth.theboss.io/auth/realms/BOSS"
 #client_id = "<auth client id>" # Client ID configured in the Auth Server
 #public_uri = "http://localhost:8000" 
 #The address that the client will be redirected back to
 #NOTE: the public uri needs to be configured in the Auth Server
 #as a valid uri to redirect to
scope = ['openid', 'profile', 'email', 'number', 'data'] # NOTE: This is the default scope if one is not provided

from bossoidc.settings import *
configure_oidc(auth_uri, client_id, public_uri, scope) 

but it always gives me the same problem:

configure_oidc(auth_uri, client_id, public_uri, scope)  NOTE: scope is optional and can be left out
TypeError: configure_oidc() takes 3 positional arguments but 4 were given
derek-pryor commented 6 years ago

@Giovanni-94 please make sure you are running the latest version of the code. The change to configure_oidc to add the fourth argument was just added a week ago.

Allan-Nava commented 6 years ago

How can we update the library?

Inviato da iPhone

Il giorno 18 dic 2017, alle ore 23:29, Derek Pryor notifications@github.com ha scritto:

@Giovanni-94 please make sure you are running the latest version of the code. The change to configure_oidc to add the fourth argument was just added a week ago.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

derek-pryor commented 6 years ago

Probably the same way you installed it...

pip install git+https://github.com/jhuapl-boss/boss-oidc.git

On Mon, Dec 18, 2017 at 3:46 PM, Allan Nava notifications@github.com wrote:

How can we update the library?

Inviato da iPhone

Il giorno 18 dic 2017, alle ore 23:29, Derek Pryor < notifications@github.com> ha scritto:

@Giovanni-94 please make sure you are running the latest version of the code. The change to configure_oidc to add the fourth argument was just added a week ago.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jhuapl-boss/boss-oidc/issues/3#issuecomment-352594110, or mute the thread https://github.com/notifications/unsubscribe-auth/AO6WUx46nFVs9kTWuVGPPzXwKy378-59ks5tBvlOgaJpZM4Q0TQK .

Allan-Nava commented 6 years ago

Ok now we try! Thanks for support @derek-pryor

Giovanni-94 commented 6 years ago

Thank you very much @derek-pryor , unfortunately when I installed the latest version, compiler tells me requirement already satisfied :

Requirement already satisfied: cffi>=1.7; platform_python_implementation != "PyPy" in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from cryptography>=2.1.4->pyOpenSSL->oic>=0.7.6->boss-oidc==0.1)
Requirement already satisfied: pycparser in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from cffi>=1.7; platform_python_implementation != "PyPy"->cryptography>=2.1.4->pyOpenSSL->oic>=0.7.6->boss-oidc==0.1)
derek-pryor commented 6 years ago

If you are updating boss-oidc you should see messages saying that each of the dependencies are satisfied, as they are already installed. You should see a message about boss-oidc being uninstalled and then installed. You will know if the update works if you don't get the same error.

On Tue, Dec 19, 2017 at 12:46 AM, Giovanni-94 notifications@github.com wrote:

Thank you very much derek, unfortunately when I installed the latest version, compiler tells me requirement already satisfied :

Requirement already satisfied: cffi>=1.7; platform_python_implementation != "PyPy" in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from cryptography>=2.1.4->pyOpenSSL->oic>=0.7.6->boss-oidc==0.1) Requirement already satisfied: pycparser in /Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages (from cffi>=1.7; platform_python_implementation != "PyPy"->cryptography>=2.1.4->pyOpenSSL->oic>=0.7.6->boss-oidc==0.1)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/jhuapl-boss/boss-oidc/issues/3#issuecomment-352677358, or mute the thread https://github.com/notifications/unsubscribe-auth/AO6WU13_r4zogYdELuy6P3SUCkJR7eJhks5tB3gBgaJpZM4Q0TQK .

Giovanni-94 commented 6 years ago

Ok I understand, @derek-pryor could you tell me the right command to uninstall the old version?

Allan-Nava commented 6 years ago
  Cloning https://github.com/jhuapl-boss/boss-oidc.git to /tmp/pip-k5sw4bp_-build
  Requirement already satisfied (use --upgrade to upgrade): boss-oidc==0.1 from git+https://github.com/jhuapl-boss/boss-oidc.git in /usr/local/lib/python3.5/dist-packages
Requirement already satisfied: django>=1.8 in /usr/local/lib/python3.5/dist-packages (from boss-oidc==0.1)
Requirement already satisfied: djangorestframework>=2.4.0 in /usr/local/lib/python3.5/dist-packages (from boss-oidc==0.1)
Requirement already satisfied: oic>=0.7.6 in /usr/local/lib/python3.5/dist-packages (from boss-oidc==0.1)
Requirement already satisfied: django-oidc>=0.1.3 in /usr/local/lib/python3.5/dist-packages (from boss-oidc==0.1)
Requirement already satisfied: drf-oidc-auth>=0.8 in /usr/local/lib/python3.5/dist-packages (from boss-oidc==0.1)
Requirement already satisfied: pytz in /usr/local/lib/python3.5/dist-packages (from django>=1.8->boss-oidc==0.1)
Requirement already satisfied: requests in /usr/local/lib/python3.5/dist-packages (from oic>=0.7.6->boss-oidc==0.1)
Requirement already satisfied: pycryptodomex in /usr/local/lib/python3.5/dist-packages (from oic>=0.7.6->boss-oidc==0.1)
Requirement already satisfied: pyjwkest>=1.3.6 in /usr/local/lib/python3.5/dist-packages (from oic>=0.7.6->boss-oidc==0.1)
Requirement already satisfied: mako in /usr/local/lib/python3.5/dist-packages (from oic>=0.7.6->boss-oidc==0.1)
Requirement already satisfied: beaker in /usr/local/lib/python3.5/dist-packages (from oic>=0.7.6->boss-oidc==0.1)
Requirement already satisfied: alabaster in /usr/local/lib/python3.5/dist-packages (from oic>=0.7.6->boss-oidc==0.1)
Requirement already satisfied: pyOpenSSL in /usr/local/lib/python3.5/dist-packages (from oic>=0.7.6->boss-oidc==0.1)
Requirement already satisfied: future in /usr/local/lib/python3.5/dist-packages (from oic>=0.7.6->boss-oidc==0.1)
Requirement already satisfied: six in /usr/local/lib/python3.5/dist-packages (from oic>=0.7.6->boss-oidc==0.1)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/lib/python3.5/dist-packages (from requests->oic>=0.7.6->boss-oidc==0.1)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/lib/python3.5/dist-packages (from requests->oic>=0.7.6->boss-oidc==0.1)
Requirement already satisfied: idna<2.7,>=2.5 in /usr/local/lib/python3.5/dist-packages (from requests->oic>=0.7.6->boss-oidc==0.1)
Requirement already satisfied: urllib3<1.23,>=1.21.1 in /usr/local/lib/python3.5/dist-packages (from requests->oic>=0.7.6->boss-oidc==0.1)
Requirement already satisfied: MarkupSafe>=0.9.2 in /usr/local/lib/python3.5/dist-packages (from mako->oic>=0.7.6->boss-oidc==0.1)
Requirement already satisfied: cryptography>=1.9 in /usr/local/lib/python3.5/dist-packages (from pyOpenSSL->oic>=0.7.6->boss-oidc==0.1)
Requirement already satisfied: cffi>=1.7 in /usr/local/lib/python3.5/dist-packages (from cryptography>=1.9->pyOpenSSL->oic>=0.7.6->boss-oidc==0.1)
Requirement already satisfied: asn1crypto>=0.21.0 in /usr/local/lib/python3.5/dist-packages (from cryptography>=1.9->pyOpenSSL->oic>=0.7.6->boss-oidc==0.1)
Requirement already satisfied: pycparser in /usr/local/lib/python3.5/dist-packages (from cffi>=1.7->cryptography>=1.9->pyOpenSSL->oic>=0.7.6->boss-oidc==0.1)

This is the latest version accessible with Django 1.11.5 and this command: pip3 install git+https://github.com/jhuapl-boss/boss-oidc.git

Is there anyway to make this customization by my self?

Allan-Nava commented 6 years ago

Hi @derek-pryor ,

any news?

derek-pryor commented 6 years ago

News about what?

You can update the plugin using pip3 install --upgrade git+https://github.com/jhuapl-boss/boss-oidc.git which will allow you to add code to handle an increase in scope response.

As to the original issue with JSON serialization, you can add the following block of code to settings.py to get some debugging information about what is going on.

LOGGING = {
    'version': 1,
    'disable_existing_loggers': False,
    'handlers': {
        'console': { 'class':'logging.StreamHandler' }
    },
    'loggers': {
        'djangooidc.oidc': { 'level': 'DEBUG' }
    }
}

As to the mapper issue, I don't understand what you are referencing. Is it something in Django, Keycloak, something else? In either case it seems like it may be a problem that is out of scope for this plugin.

Allan-Nava commented 6 years ago

Ok now I try with this: pip3 install --upgrade git+https://github.com/jhuapl-boss/boss-oidc.git

Giovanni-94 commented 6 years ago

Hi @derek-pryor, I did what you said and I upgrade, but I have this error:


Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x10d7c8840>
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/autoreload.py", line 226, in wrapper
    fn(*args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/commands/runserver.py", line 116, in inner_run
    self.check(display_num_errors=True)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/management/base.py", line 426, in check
    include_deployment_checks=include_deployment_checks,
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/checks/registry.py", line 75, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/checks/urls.py", line 10, in check_url_config
    return check_resolver(resolver)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/checks/urls.py", line 19, in check_resolver
    for pattern in resolver.url_patterns:
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/functional.py", line 33, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/urlresolvers.py", line 417, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/utils/functional.py", line 33, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/core/urlresolvers.py", line 410, in urlconf_module
    return import_module(self.urlconf_name)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Users/giovannicozzi/Desktop/kcdj/lol/keycloakexample/keycloakexample/urls.py", line 29, in <module>
    url(r'openid/', include('djangooidc.urls')),
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/django/conf/urls/__init__.py", line 52, in include
    urlconf_module = import_module(urlconf_module)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 994, in _gcd_import
  File "<frozen importlib._bootstrap>", line 971, in _find_and_load
  File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 678, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/djangooidc/urls.py", line 4, in <module>
    from . import views
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/djangooidc/views.py", line 59
    except Exception, e:
                    ^
SyntaxError: invalid syntax
derek-pryor commented 6 years ago

@Giovanni-94 What version of django-oidc are you running (where did you install it from)? The jhuapl-boss version (https://github.com/jhuapl-boss/django-oidc.git) has had that issue fixed since March 2016.

Giovanni-94 commented 6 years ago

The version was 1.9.2

Allan-Nava commented 6 years ago

Hi @derek-pryor , I have this error, when I try to integrate sms authenticator:

Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7f27d4134ea0>
Traceback (most recent call last):
  File "/usr/local/lib/python3.5/dist-packages/django/utils/autoreload.py", line 228, in wrapper
    fn(*args, **kwargs)
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/commands/runserver.py", line 125, in inner_run
    self.check(display_num_errors=True)
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 359, in check
    include_deployment_checks=include_deployment_checks,
  File "/usr/local/lib/python3.5/dist-packages/django/core/management/base.py", line 346, in _run_checks
    return checks.run_checks(**kwargs)
  File "/usr/local/lib/python3.5/dist-packages/django/core/checks/registry.py", line 81, in run_checks
    new_errors = check(app_configs=app_configs)
  File "/usr/local/lib/python3.5/dist-packages/django/core/checks/urls.py", line 16, in check_url_config
    return check_resolver(resolver)
  File "/usr/local/lib/python3.5/dist-packages/django/core/checks/urls.py", line 26, in check_resolver
    return check_method()
  File "/usr/local/lib/python3.5/dist-packages/django/urls/resolvers.py", line 254, in check
    for pattern in self.url_patterns:
  File "/usr/local/lib/python3.5/dist-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python3.5/dist-packages/django/urls/resolvers.py", line 405, in url_patterns
    patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
  File "/usr/local/lib/python3.5/dist-packages/django/utils/functional.py", line 35, in __get__
    res = instance.__dict__[self.name] = self.func(instance)
  File "/usr/local/lib/python3.5/dist-packages/django/urls/resolvers.py", line 398, in urlconf_module
    return import_module(self.urlconf_name)
  File "/usr/lib/python3.5/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 986, in _gcd_import
  File "<frozen importlib._bootstrap>", line 969, in _find_and_load
  File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 673, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 665, in exec_module
  File "<frozen importlib._bootstrap>", line 222, in _call_with_frames_removed
  File "/home/ies/bootcamp/bootcamp/urls.py", line 21, in <module>
    from djangooidc import urls
  File "/usr/local/lib/python3.5/dist-packages/djangooidc/urls.py", line 4, in <module>
    from . import views
  File "/usr/local/lib/python3.5/dist-packages/djangooidc/views.py", line 21, in <module>
    CLIENTS = OIDCClients(settings)
  File "/usr/local/lib/python3.5/dist-packages/djangooidc/oidc.py", line 148, in __init__
    self.client[key] = self.create_client(**val)
  File "/usr/local/lib/python3.5/dist-packages/djangooidc/oidc.py", line 221, in create_client
    _ = client.provider_config(kwargs["srv_discovery_url"])
  File "/usr/local/lib/python3.5/dist-packages/oic/oic/__init__.py", line 1034, in provider_config
    "Trying '%s', status %s" % (url, r.status_code))
oic.exception.CommunicationError: Trying 'http://login.livereporter.com:8080/auth/realms/django/.well-known/openid-configuration', status 404
derek-pryor commented 6 years ago

Since there have not been any comments related to the original error I am closing this issue. Without more debugging information I cannot help with the original issue. If there is still a problem with either the original error or any of the other problems discussed open a new issue.