Beispiel #1
0
def get_or_create_app(name,
                      redirect_uri,
                      user,
                      client_id=None,
                      client_secret=None):
    """
    Get or creates an OAuth2 application.
    """
    try:
        application = Application.objects.get(name=name)
    except Application.DoesNotExist:
        application = Application()

    application.user = user

    if client_id and client_secret:
        application.client_id = client_id
        application.client_secret = client_secret

    application.name = name
    application.authorization_grant_type = Application.GRANT_AUTHORIZATION_CODE
    application.client_type = Application.CLIENT_CONFIDENTIAL
    application.redirect_uris = redirect_uri

    application.save()

    return application
def add_auth(entity, user, form):
    if "client_id" in form.cleaned_data:
        if "client_secret" in form.cleaned_data:
            if "token_end_point" in form.cleaned_data:
                id = form.cleaned_data['client_id']
                secret = form.cleaned_data['client_secret']
                end_point = form.cleaned_data['token_end_point']
                
                client = OAuthRemoteClient()
                client.client_id = id
                client.client_secret = secret
                client.token_endpoint = end_point
                client.entity = entity
                client.save()
    
    application = Application()
    application.user = user
    application.client_type = 'confidential'
    application.authorization_grant_type = 'client-credentials'
    application.name = entity.name
    application.save()
    
    entityOA = EntityOAuth()
    entityOA.entity = entity
    entityOA.application = application
    entityOA.save()
Beispiel #3
0
 def createApplication(self, user, name, id, secret):
     application = Application()
     application.user = user
     application.client_type = 'confidential'
     application.authorization_grant_type = 'password'
     application.name = name
     application.client_id = id
     application.client_secret = secret
     application.save()
 def createApplication(self, user, name, id, secret):
     application = Application()
     application.user = user
     application.client_type = 'confidential'
     application.authorization_grant_type = 'password'
     application.name = name
     application.client_id = id
     application.client_secret = secret
     application.save()
Beispiel #5
0
    def create_jwt_app(self) -> Application:
        """Create a jwt application."""
        app = Application()
        app.name = self.jwt_app_name
        app.client_type = Application.CLIENT_CONFIDENTIAL
        app.authorization_grant_type = Application.GRANT_PASSWORD
        app.save()

        return app
Beispiel #6
0
 def create_app():
     try:
         result = Application.objects.get(client_id=settings.TEST_CLIENT_ID)
     except Application.DoesNotExist:
         result = Application(client_id=settings.TEST_CLIENT_ID, )
     result.name = settings.TEST_CLIENT_NAME
     result.client_secret = settings.TEST_CLIENT_SECRET
     result.redirect_uris = settings.TEST_REDIRECT_URIS
     result.client_type = Application.CLIENT_CONFIDENTIAL
     result.authorization_grant_type = Application.GRANT_AUTHORIZATION_CODE
     result.save()
     return result
Beispiel #7
0
def create_user_settings(sender, instance=None, created=False, **kwargs):
    """ For created user, creating Application instance for oauth2 model,
        use 'client_type = public' for authorization with client_id without client_secret,
        and 'grant_type = password' for password authenticate.
        Value for variable from oauth source code.
    """
    if created:
        app = Application()
        app.user = instance
        app.name = 'default'
        app.authorization_grant_type = 'password'
        app.client_type = 'public'
        app.save()
Beispiel #8
0
    def save(self, *args, **kwargs):
        if hasattr(self, "application"):
            application = self.application
        else:
            application = Application()

        application.name = self.name
        application.user = self.coordinator.user
        application.client_type = Application.CLIENT_CONFIDENTIAL
        application.redirect_uris = self.redirect_url
        application.authorization_grant_type = Application.GRANT_AUTHORIZATION_CODE

        application.save()

        self.application = application

        super(OAuth2DataRequestProject, self).save(*args, **kwargs)
    def save(self, *args, **kwargs):
        if hasattr(self, "application"):
            application = self.application
        else:
            application = Application()

        application.name = self.name
        application.user = self.coordinator.user
        application.client_type = Application.CLIENT_CONFIDENTIAL
        application.redirect_uris = self.redirect_url
        application.authorization_grant_type = Application.GRANT_AUTHORIZATION_CODE

        application.save()

        self.application = application

        super(OAuth2DataRequestProject, self).save(*args, **kwargs)
Beispiel #10
0
    def crearApilicationOauthAndroid(self):
        if (Application.objects.filter(name='Android')):
            print('[+] Aplicacion Android ya existe')
        else:
            aplication = Application()
            aplication.name = 'Android'
            aplication.client_id = 'NxZCC1cyEC4EaKWTp0WOKI8AcfxoLympY6ESrQFi'
            aplication.client_secret = 'gcogobaJ4lYihODys8U9ij7BUQBbx8Uta3GVo3AVpnFcSNtDi9rg1LElTOfttDMSqh3hyjEIHFyTzrD9J48yl5lEKOXShf13vPUrGQFLr7gRAZqu8264KWd5YrShqIby'
            aplication.client_type = 'confidential'
            aplication.redirect_uris = ''
            aplication.authorization_grant_type = 'password'

            try:

                aplication.save()

                print('[+] Registro de Aplicacion creado')
            except:
                print('[+][+] Registro de Aplicacion no es valida')
                print('[+][+] Error en registro de Aplicacion -> ' +
                      aplication.__repr__())
Beispiel #11
0
    def crearApilicationOauthAngular(self):
        if (Application.objects.filter(name='Angular')):
            print('[+] Aplicacion Angular ya existe')
        else:
            aplication = Application()
            aplication.name = 'Angular'
            aplication.client_id = 'xIlTUtu3pv3YCN0NZxioinzAIvnqhaUPB3j6C9m1'
            aplication.client_secret = '15VmSMITKwQTOdDxSfUtFa6SGhvSkhRbtumDSJssPaOvhL1BJAoql5SCM6EVGdEPEubougfrpR3f29GoPDhgeez3o9kWlSQFRsd03wiJiHz9Wlgp9V61y8tdom0XyZoj'
            aplication.client_type = 'confidential'
            aplication.redirect_uris = ''
            aplication.authorization_grant_type = 'password'

            try:

                aplication.save()

                print('[+] Registro de Aplicacion creado')
            except:
                print('[+][+] Registro de Aplicacion no es valida')
                print('[+][+] Error en registro de Aplicacion -> ' +
                      aplication.__repr__())
Beispiel #12
0
    def form_valid(self, form):
        if Application.objects.filter(name=form.cleaned_data["application_name"]).exists():
            messages.warning(self.request, "Application with this name already exists.")
        else:
            oapp = OAuthApplication()
            oapp.description = form.cleaned_data["description"]
            oapp.website = form.cleaned_data["website"]

            omodel = Application()
            omodel.user = self.request.user
            omodel.redirect_uris = form.cleaned_data["callback_url"]
            omodel.client_type = "confidential"
            omodel.authorization_grant_type = "authorization-code"
            omodel.name = form.cleaned_data["application_name"]
            omodel.save()

            oapp.client = omodel
            oapp.save()

            messages.success(self.request, "Application Created!")

        return super(OAuthClientCreateView, self).form_valid(form)
def get_or_create_app(name, redirect_uri, user, client_id=None, client_secret=None):
    """
    Get or creates an OAuth2 application.
    """
    try:
        application = Application.objects.get(name=name)
    except Application.DoesNotExist:
        application = Application()

    application.user = user

    if client_id and client_secret:
        application.client_id = client_id
        application.client_secret = client_secret

    application.name = name
    application.authorization_grant_type = Application.GRANT_AUTHORIZATION_CODE
    application.client_type = Application.CLIENT_CONFIDENTIAL
    application.redirect_uris = redirect_uri

    application.save()

    return application