WP Manifestindependent plugin directory
manifest / security / telia-strong-authentication-wp-plugin

Strong authentication provided by Telia

Telia tunnistautuminen (Strong authentication), a WordPress Plugin for restricted accesses like specific page sections, blocks, and forms.

★ 0stars
1.0.0latest · 3 years ago

Install

Download source zip No release zip yet

This is the repository archive. It installs, but the folder name will carry the branch suffix and updates will not flow.

Install straight from GitHub with WP-CLI:

wp plugin install https://github.com/jussipalanen/telia-strong-authentication-wp-plugin/archive/refs/heads/main.zip
No built-in updater. New versions won't appear under Dashboard → Updates. Install new releases yourself, or let Git Updater track the repository.

Telia tunnistautuminen - Strong authentication

Telia strong customer authentication and integration for WordPress forms and custom functionalities.

Requirements

Required environment variables

  • TELIA_SCA_MODE Environment mode (demo | production)
  • TELIA_SCA_CLIENT_ID Unique Client ID for the API requests
  • TELIA_SCA_REDIRECT_URL Redirect URL after authentication service
    • Example (for production): # TELIA_SCA_REDIRECT_URL='https://localhost/telia-api/response/'
    • Example (for staging or local development): # TELIA_SCA_REDIRECT_URL='https://localhost/telia-api/response/'

Usage and examples

If you want to use the authentication URL on your forms or custom functionalities. You can use the following global plugin function: Telia_SCA to use the class functions of this instance.

Authentication Submit URL

Get the authentication URL e.g. for your form, use this function.

Method #1

<?php 
use function JussiNet\TeliaSCA\Telia_SCA;

# Get the protected submit URL, this does not show the real URL of the authentication
$auth_url = Telia_SCA()::instance()->oauth2()->getSubmitUrl();
?>

<h1>Example form</h1>
<p>Description</p>
<a href="<?php echo $auth_url; ?>">Authenticate</a>

Method #2

<h1>Authentication form</h1>
<p>Description</p>
<form action="<?php echo $auth_url ;?>" method="post">
    <input type="submit" value="Authenticate">
</form>

Restricted views

If you want to restrict the views, which show the content before and after authentication.

<?php 
use function JussiNet\TeliaSCA\Telia_SCA;
$auth_url = Telia_SCA()::instance()->oauth2()->getSubmitUrl();

# Show the form or content after authentication
# If the user has not already authed, then show the authentication form 
if (Telia_SCA()::instance()->helper()->isUserAuthed()) : >

    <?php 
    # Get the user info model class and fetch data from the stored data "session".
    $userInfo = Telia_SCA()::instance()->helper()->getUserInfo();
    >
    <h1>User form</h1>
    <form action="{{ $your_form_post_url }}" post="POST">
        <label>Firstname</label>
        <input type="text" name=="firstname" value="<?php echo $userInfo->getFirstname(); ?>">

        <label>Lastname</label>
        <input type="text" name=="lastname" value="<?php echo $userInfo->getLastname(); ?>">

        <label>Email</label>
        <input type="text" name=="email" value="<?php echo $userInfo->getEmail(); ?>">

        <label>Phone</label>
        <input type="text" name=="phone" value="<?php echo $userInfo->getEmail(); ?>">

        <input type="submit" value="Submit this form">
    </form>
<?php else: ?>
    <h1>Authentication form</h1>
    <p>Description</p>
    <a href="<?php echo $auth_url; ?>">Authenticate</a>
<?php endif; ?>

If you want give the parameters for the custom form redirects.

$auth_url = Telia_SCA()::instance()->oauth2()->getSubmitUrl([
    'redirect_url' => get_permalink( $post ), # If this value is null or not given, then get the current page
    'succcess_url' => get_permalink( $post ), # Optional
    'error_url' => get_permalink( $post ) # Optional
]);

Other details (optional)

Attention! If the keys are not working, outdated, or corrupted, do this. The private key "RSA" is required for authorization and fetching the userinfo from the Telia API (OpenId Connect). If the RSA private keys are missing, please generate them. You must also contact Telia's customer service to allow your hostname or IP address.

  • Generate the private key (.pem) openssl genpkey -algorithm RSA -aes-256-cbc -outform PEM -out private_key.pem -pkeyopt rsa_keygen_bits:2048.

    • Save it under directory /keys/{development}_private_key.pem
  • Convert the private key (.pem) into the public key (.pem). openssl rsa -in private_key.pem -pubout > public.pem

    • Save it under directory /keys/{development}_public_key.pem
  • Convert the private key (.pem) into the RSA private key. openssl rsa -in private_key.pem -out private_rsa_key.key

    • Save it under directory /keys/{development}_private_rsa_key.key
  • Convert the RSA private key into the JWKs in JSON format. You can use this link to convert pem to jwk. https://irrte.ch/jwt-js-decode/pem2jwk.html

  • Save the .json file under /json/{development}.json

Documentation

See docs directory for additional documentation.

Releases

1 release.

Tag
Published
1.0.0 latest
Sep 11, 2023 3 years ago

These releases are tags only. The author does not attach a packaged zip, so there are no download counts to report.