Confirm client connection attempt and associate new session with currently
selected account preset
@instance
@category async
@return {Promise<String>} Session ID
518112
async function hello () {
  const id = await Rpc.compose.deepProperties.rpcMethods.hello.call(this)
  this.rpcSessions[id].address = await this.address()
  return Promise.resolve(id)
}
1336455
function(){
			var d = new Deferred();
			this._preferenceService.get(this._prefix).then(
				function(pref){
					var userInfo = pref["userInfo"]; //$NON-NLS-0$
					d.resolve(userInfo);
				}
			);
			return d;
		}
1171878
def current_account=(new_account)
      if self.auth_type_used != :basic
        session[:account_id] = (new_account.nil? || new_account.is_a?(Symbol)) ? nil : new_account.id
      end
      @current_account = new_account || :false
    end
1224660
async function deferSession(ctx, next) {
    ctx.sessionStore = store

    // TODO:
    // Accessing ctx.session when it's defined is causing problems
    // because it has side effect. So, here we use a flag to determine
    // that session property is already defined.
    if (ctx.__isSessionDefined) {
      return next()
    }
    let isNew = false
    let originalHash = null
    let touchSession = false
    let getter = false

    // if path not match
    if (!matchPath(ctx)) {
      return next()
    }

    addCommonAPI(ctx)

    Object.defineProperty(ctx, 'session', {
      async get() {
        if (touchSession) {
          return this._session
        }
        touchSession = true
        getter = true

        const result = await getSession(this)
        // if cookie path not match
        // this route's controller should never use session
        if (!result) return

        originalHash = result.originalHash
        isNew = result.isNew
        this._session = result.session
        return this._session
      },
      set(value) {
        touchSession = true
        this._session = value
      }
    })

    // internal flag to determine that session is already defined
    ctx.__isSessionDefined = true

    ctx.regenerateSession = async function regenerateSession() {
      debug('regenerating session')
      // make sure that the session has been loaded
      await ctx.session

      if (!isNew) {
        // destroy the old session
        debug('destroying previous session')
        await store.destroy(ctx.sessionId)
      }

      ctx._session = generateSession()
      ctx.sessionId = genSid.call(ctx, 24)
      sessionIdStore.reset.call(ctx)
      debug('created new session: %s', ctx.sessionId)
      isNew = true
      return ctx._session
    }

    await next()

    if (touchSession) {
      // if only this.session=, need try to decode and get the sessionID
      if (!getter) {
        ctx.sessionId = sessionIdStore.get.call(ctx)
      }

      await refreshSession(ctx, ctx._session, originalHash, isNew)
    }
  }
157406
async function authenticate(scopes) {
  return new Promise((resolve, reject) => {
    // grab the url that will be used for authorization
    const authorizeUrl = oauth2Client.generateAuthUrl({
      access_type: 'offline',
      scope: scopes.join(' '),
    });
    const server = http
      .createServer(async (req, res) => {
        try {
          if (req.url.indexOf('/oauth2callback') > -1) {
            const qs = new url.URL(req.url, 'http://localhost:3000')
              .searchParams;
            res.end('Authentication successful! Please return to the console.');
            server.destroy();
            const {tokens} = await oauth2Client.getToken(qs.get('code'));
            oauth2Client.credentials = tokens;
            resolve(oauth2Client);
          }
        } catch (e) {
          reject(e);
        }
      })
      .listen(3000, () => {
        // open the browser to the authorize url to start the workflow
        opn(authorizeUrl, {wait: false}).then(cp => cp.unref());
      });
    destroyer(server);
  });
}
63812
function sessionCreated(err, session) {
  var agentInfo = {name: ping + "er", title: "a " + ping + "er" }

  session.createAgent(agentInfo, function(err, agent) {
    console.log(ping + " agent created")

    agent.receive(ping, function(body, reply) {
      reply(null, body)
      bong()
    })
  })

  session.on("ragentCreated", function(ragent) {
    ragentCreated(ragent, "created")
  })

  session.getRemoteAgents(function(err, ragents){
    ragents.forEach(function(ragent) {
      ragentCreated(ragent, "existed")
    })
  })
}
1116549
function updateAccount() {

  account.middleName = 'Make it so.';

  return account.save(function(err, savedAccount) {
    if (err) throw err;
    account = savedAccount;
    console.log('Updated account:');
    console.log(account);
    return authenticateAccount(); //next quickstart step
  });

}
311364
function(callback){
			if(!this.id){
				return process.nextTick(function(){
					callback(new Error("Invalid session ID"));
				});
			}
			options.client.expire(options.keyspace + this.id, options.maxAge, callback);
		}
315910
async function getSession(ctx) {
    if (!matchPath(ctx)) return
    if (storeStatus === 'pending') {
      debug('store is disconnect and pending')
      await waitStore
    } else if (storeStatus === 'unavailable') {
      debug('store is unavailable')
      throw new Error('session store is unavailable')
    }

    if (!ctx.sessionId) {
      ctx.sessionId = sessionIdStore.get.call(ctx)
    }

    let session
    let isNew = false
    if (!ctx.sessionId) {
      debug('session id not exist, generate a new one')
      session = generateSession()
      ctx.sessionId = genSid.call(ctx, 24)
      isNew = true
    } else {
      try {
        session = await store.get(ctx.sessionId)
        debug('get session %j with key %s', session, ctx.sessionId)
      } catch (err) {
        if (err.code === 'ENOENT') {
          debug('get session error, code = ENOENT')
        } else {
          debug('get session error: ', err.message)
          errorHandler(err, 'get', ctx)
        }
      }
    }

    // make sure the session is still valid
    if (!session ||
      !valid(ctx, session)) {
      debug('session is empty or invalid')
      session = generateSession()
      ctx.sessionId = genSid.call(ctx, 24)
      sessionIdStore.reset.call(ctx)
      isNew = true
    }

    // get the originHash
    const originalHash = !isNew && hash(session)

    return {
      originalHash: originalHash,
      session: session,
      isNew: isNew
    }
  }
391280
function __process_authorization_header_for_client(request_params) {
    return new Promise(async (resolve, reject) => {
        try {
            const client_account_id = await client_endpoint
                .client_registrar_module
                .get_client_account_id_for_credentials(request_params.authorization_credentials.username, request_params.authorization_credentials.password);

            return resolve(request_params);
        } catch (err) {
            return reject(new Error("Unauthorized request"));
        }
    });
}
323412
function () {
            var result = new $.Deferred();
            this.storage.load()
                .then(function (data) {
                    var oldKeys = this.getKeys();
                    this.data = data;
                    result.resolve();
                    this.trigger(PREFERENCE_CHANGE, {
                        ids: _.union(this.getKeys(), oldKeys)
                    });
                }.bind(this))
                .fail(function (error) {
                    result.reject(error);
                });
            return result.promise();
        }
872959
function assertContext() {
  return new Promise(function(resolve, reject) {
    // Check if we're in an active session
    let d = process.domain
    if (d == null ||
        d.context == null ||
        d.context.bardo == null) {
      // Begin the session before proceeding
      return begin().then((ctx) => {
        resolve(ctx)
      }).catch(reject)
    }

    // Continue onwards with our active domain
    return resolve(d.context.bardo)
  })
}
468570
function identifyUser(req, res, next) {
  // Get the session ID from the session cookie
  var sessionId = req.cookies.session;
  req.session = null;

  if (sessionId) {
    // Get the session REST resource
    var resource = new swagger.Resource('/sessions', sessionId, null);
    req.app.dataStore.get(resource, function(err, resource) {
      if (resource) {
        // Add the session to the request, so other middleware can use it
        req.session = resource.data;
        console.log('Current User: %s', req.session.user.username);
      }
      else {
        console.warn('INVALID SESSION ID: ' + sessionId);
      }
      next();
    });
  }
  else {
    console.log('Current User: ANONYMOUS');
    next();
  }
}
1171725
def request_session(self):
        
        concierge_request_header = self.construct_concierge_header(
            url="http://membersuite.com/contracts/IConciergeAPIService/WhoAmI")

        result = self.client.service.WhoAmI(
            _soapheaders=[concierge_request_header])

        self.session_id = get_session_id(result=result)

        if not self.session_id:
            raise MembersuiteLoginError(
                result["body"]["WhoAmIResult"]["Errors"])

        return self.session_id
808488
async function session(ctx, next) {
    ctx.sessionStore = store
    if (ctx.session || ctx._session) {
      return next()
    }
    const result = await getSession(ctx)
    if (!result) {
      return next()
    }

    addCommonAPI(ctx)

    ctx._session = result.session

    // more flexible
    Object.defineProperty(ctx, 'session', {
      get() {
        return this._session
      },
      set(sess) {
        this._session = sess
      }
    })

    ctx.regenerateSession = async function regenerateSession() {
      debug('regenerating session')
      if (!result.isNew) {
        // destroy the old session
        debug('destroying previous session')
        await store.destroy(ctx.sessionId)
      }

      ctx.session = generateSession()
      ctx.sessionId = genSid.call(ctx, 24)
      sessionIdStore.reset.call(ctx)

      debug('created new session: %s', ctx.sessionId)
      result.isNew = true
    }

    // make sure `refreshSession` always called
    let firstError = null
    try {
      await next()
    } catch (err) {
      debug('next logic error: %s', err.message)
      firstError = err
    }
    // can't use finally because `refreshSession` is async
    try {
      await refreshSession(ctx, ctx.session, result.originalHash, result.isNew)
    } catch (err) {
      debug('refresh session error: %s', err.message)
      if (firstError) ctx.app.emit('error', err, ctx)
      firstError = firstError || err
    }
    if (firstError) throw firstError
  }
710798
def get_new_client(request_session=False):
    
    from .client import ConciergeClient
    client = ConciergeClient(access_key=os.environ["MS_ACCESS_KEY"],
                             secret_key=os.environ["MS_SECRET_KEY"],
                             association_id=os.environ["MS_ASSOCIATION_ID"])
    if request_session:
        client.request_session()
    return client
858044
function (changes, cb) {
        var self = this;

        this._log('info', 'Initiating incoming session');

        this.state = 'pending';

        this.pc.isInitiator = false;
        this.pc.handleOffer({
            type: 'offer',
            jingle: changes
        }, function (err) {
            if (err) {
                self._log('error', 'Could not create WebRTC answer');
                return cb({condition: 'general-error'});
            }
            cb();
        });
    }