GithubHelp home page GithubHelp logo

Comments (1)

ruwanta avatar ruwanta commented on June 23, 2024

Documentation

Usually you will want to generate new claims or change a claim value after an existing authentication is successful.
E.g.
Generate the “Display Name” when you have “First Name” and “Last Name”
Generate “Age” when you have “Date Of Birth”

You are provided two array view of the claims

  • Array view with local claim URI
  • Array view with remote claim URI

Accessing a claim by local claim uri

var myClaimValueX = context.subject.claims.local['http://wso2.org/claims/<x>];

Accessing a claim by remote claim uri

var myClaimValueX = context.subject.claims.remote['http://some.domain.you/claims/<x>];

Adding a new claim to the claim set

var newClaim = {}
//Populate claim values, remote and local URI with valid value.
...
context.subject.claims.push(newClaim)

Example

Create the "Display Name" and attach it as a new claim, by using the first name and last name of the authenticated user.

function onInitialRequest (context) {
   executeStep({id :'1',
       on : {
           success : function(context) {
               Log.info('First Authentication success');
               var fName = context.subject.claims.local['http://wso2.org/claims/givenname'];
               var lName = context.subject.claims.local['http://wso2.org/claims/lastname'];
               var displayName = fName + ' '+ lName + ' by Javascript';
               var newClaim = {'local' : {}, 'remote': {}};
               newClaim.remote.uri = 'http://your.domain.some/claims/displayName';
               newClaim.local.uri = 'http://wso2.org/claims/displayName';
               newClaim.value = displayName;

               Log.info('Display Name: '+displayName);
               context.subject.claims.push(newClaim)
           }
       }
   });
}

from carbon-identity-framework.

Related Issues (20)

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.