Table of Contents
Just a second...

Change the security principal and credentials associated with your client session

A client session can change the credentials it uses to authenticate with the Diffusion™ server at any time.

JavaScript
    session.security.changePrincipal('admin', 'password').then(function() {
        console.log('Authenticated as admin');
    });
Apple
    [_session.security changePrincipal:@"somePrincipalWithAuthority"
                           credentials:[[PTDiffusionCredentials alloc] initWithPassword:@"s3cret"]
                     completionHandler:^(NSError *const error)
     {
         if (error) {
             NSLog(@"Failed to change principal: %@", error);
         }
     }];
					
Java and Android
        security = session.feature(Security.class);
        security.changePrincipal(
            principal,
            Diffusion.credentials().password(password),
            callback);
.NET
            security = session.GetSecurityFeature();
            security.ChangePrincipal( principal, Diffusion.Credentials.Password( password ), callback );
C
// Specify callbacks for the change_principal request.
        CHANGE_PRINCIPAL_PARAMS_T params = {
                .principal = hash_get(options, "principal"),
                .credentials = credentials,
                .on_change_principal = on_change_principal,
                .on_change_principal_failure = on_change_principal_failure
        };

        // Do the change.
        change_principal(session, params);
When the principal associated with a session changes, the following happens:
  • The $Principal session property is updated to contain the new principal.
  • The roles associated with the old principal are removed from the session and those roles associated with the new principal are assigned to the session.
  • Topic subscriptions made with the old principal are not re-evaluated. The session remains subscribed to any topics the new principal does not have permissions for.