ariacom / Seal-Report

Database Reporting Tool and Tasks (.Net)
https://sealreport.org
Other
1.48k stars 478 forks source link

New enhanced SWI with JWT authentication and other improvements. #25

Closed destevetewis closed 4 years ago

destevetewis commented 4 years ago

For example, generating the JWT token from PHP using the lcobucci/jwt library:

<?php

use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Signer\Hmac\Sha256;
use Lcobucci\JWT\Signer\Key;

$time = time();

$token = (new Builder())
->issuedAt($time)
->expiresAt($time + 3600 )
->withClaim('culture','English')
->withClaim('securityGroup','Default Group')
->withClaim('username','test')
->getToken(new Sha256(),new Key('SecretKey'));

Then in the view, the token is added to the headers:

<script>
    $.ajax({
        type: "POST",
        url: url + "/SWILogin",
        headers: {
            'Authorization': 'Bearer YOUR TOKEN',
        },
        cache: false,
        success: function (data) {
            if(data.name !== undefined){
                // Login OK
            }else{
                // Login Error
                console.log(data);
            }
        }
    });
</script>