Пример #1
0
import settings
import cas

client = cas.CASClientV2(
    service_url=settings.CAS_SERVICE_URL,
    server_url=settings.CAS_SERVER_URL,
)
Пример #2
0
def logout_client_v2():
    return cas.CASClientV2(server_url='http://www.example.com/cas/')
Пример #3
0
    def __init__(self, bot: MyBot, *args, **kwargs):
        super().__init__(bot, *args, **kwargs)
        self.task: Optional[asyncio.Task] = None
        self.app = web.Application()
        self.cas_client = cas.CASClientV2(
            server_url=self.config()["cas_server_url"],
            service_url=self.config()["cas_service_url"],
        )

        self.routes = web.RouteTableDef()

        @self.routes.get('/')
        async def redirect_to_discord(request: web.Request):
            raise web.HTTPFound(self.config()['official_invite'])

        @self.routes.get('/login')
        async def login(request: web.Request):
            session = await aiohttp_session.get_session(request)

            token = request.query.get('token', None)

            if token:
                session['token'] = token

            if not session['token'] or not str(session['token']).isdigit():
                return web.Response(
                    text="Vous n'avez pas de token/token invalide.")

            token = int(session['token'])
            auth_cog = self.bot.get_cog("Authentication")

            if not token in auth_cog.auth_events.keys():
                return web.Response(
                    text=
                    "Votre token à expiré. Relancez la procédure d'authentification depuis discord."
                )

            ticket = request.query.get('ticket', None)
            user = request.query.get('user', None)

            if ticket:
                user, attributes, pgtiou = self.cas_client.verify_ticket(
                    ticket)
                if user:
                    auth_cog.auth_events[token]["info"] = {
                        "user": user,
                        "attributes": attributes
                    }
                    auth_cog.auth_events[token]["event"].set()

                    return web.Response(text="Retournez sur discord ! :)")
                    #return web.Response(text=f"Ok ? {ticket} -> user={user}, attributes={attributes}, pgtiou={pgtiou}")

            # https://cas.imtbs-tsp.eu/cas/login?service=https%3A%2F%2Fetudiants.telecom-sudparis.eu%2Flogin
            raise web.HTTPFound(self.cas_client.get_login_url())

            # return web.Response(text="Un jour, le CAS !")

        # secret_key must be 32 url-safe base64-encoded bytes
        fernet_key = fernet.Fernet.generate_key()
        secret_key = base64.urlsafe_b64decode(fernet_key)
        aiohttp_session.setup(self.app, EncryptedCookieStorage(secret_key))

        self.app.add_routes(self.routes)
        self.bot.loop.create_task(self.async_init())
Пример #4
0
def client_v2():
    return cas.CASClientV2()