Giter Club home page Giter Club logo

partner-association-post-auth-handler's Introduction

Partner Association Post Authentication Handler

This is a sample Post Authentication Handler that work alongside an Adaptive Authentication script to call a backend endpoint and associate a user attribute from the local IdP with an attribute of same physical user from a partner IdP.

To achieve this, the application (i.e. Service Provider) should send a custom parameter named 'pidp' (i.e. Partner IdP) in the authentication request with the value of an external IdP's name that is already registered with the local IdP.

NOTE: This flow is tested only with WSO2 Identity Server v5.9.0.

Table of contents

Download and install

Install from source

Prerequisites

  1. Get a clone or download source from this repository
  2. Run the Maven command mvn clean install from within the 'partner-association-post-auth-handler' directory.

Getting started

In the following instructions, WSO2 IS installation directory will be referred as <IS_HOME>

  1. Copy partner-association-post-auth-handler/target/org.wso2.carbon.identity.post.authn.handler.partnerassociation-1.0.0-SNAPSHOT to <IS_HOME>/repository/components/dropins and restart the server.
  2. Go to the 'Identity Providers' UI in IS and configure the Partner IdPs.
  3. Go to the respective Service Provider's configuration, and in 'Local & Outbound Authentication Configuration', select 'Advanced Configuration'. Under 'Authentication Step Configuration', configure Basic Authenticator for the first step. And for the 2nd step, add the registered Partner IdPs.
  4. In 'Script Based Adaptive Authentication' section, paste the following script.
    NOTE:
    • Make sure to change the pidpList variable and configure the names of the partner IdPs you have registered. 'PartnerIdP1' and 'PartnerIdP2' are used only as an example.
    • Make sure to change the attribute names to the ones returned from partner IdPs. 'xaccountId' and 'yaccountId' are used only as an example.
// Global varialble to maintain the list of registered Partner IdP names
var pidpList = ['PartnerIdP1','PartnerIdP2'];

/* Global varialble to maintain the value of 'pidp' (i.e. Partner IdP)
   parameter from the authentication request */
var pidpFromReq;

function onLoginRequest(context) {
    /* Read the 'pidp' parameter from the authentication request 
    and store it in the global variable */
    var pidpParam = context.request.params.pidp;
    if (pidpParam != null && pidpParam.length > 0) {
        pidpFromReq = pidpParam[0];
    }
    
    executeStep(1, {
        onSuccess: function (context) {
            /* If the 'pidp' is a valid IdP, execute that as the 2nd step.
               Else, ignore the 2nd step. */
            if (pidpFromReq != null && pidpList.indexOf(pidpFromReq) >= 0) {
                executeStep(2,{authenticationOptions:[{idp:pidpFromReq}]}, {
                    onSuccess: function (context) {
                        // Read the IdP specific attributes
                        var pUser = context.steps[2].subject;
                        var remoteAttr; 
                        if (context.steps[2].idp === "PartnerIdP1") {
                            remoteAttr = pUser.remoteClaims.xaccountId;
                        }
                        if (context.steps[2].idp === "PartnerIdP2") {
                            remoteAttr = pUser.remoteClaims.yaccountId;
                        }
                        /* Map the remote attribute to an attribute known by the 
                        Partner Association Post-Authentication Handler */
                        if(remoteAttr) {
                            pUser.remoteClaims.partnerAccId = remoteAttr;
                        }
                    }
                });
            } 
        }
    });
}

  1. To mock the backend service following command can be used:
    while : ; do (echo -ne "HTTP/1.1 200 OK\r\n";) | nc -l 8000 ; done
  2. Send an OIDC Request with the custom "pidp" parameter that specify the Partner IdP's name as following:
    https://<IS_HOST>:<IS_PORT>/oauth2/authorize?scope=openid&response_type=code&redirect_uri=<client-redirect-uri>&client_id=<client-id>&pidp=<idp-name>
    E.g.:
    https://localhost:9443/oauth2/authorize?scope=openid&response_type=code&redirect_uri=http://localhost:8080/playground2/oauth2client&client_id=ZHLUdHW5Jlfi21TcCTWTwxuBHO4a&pidp=PartnerIdP1

partner-association-post-auth-handler's People

Contributors

dulanjal avatar

Watchers

 avatar

partner-association-post-auth-handler's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.