Constructs a new Bridge.

@param string $credential
@param string $service
@param string $authMethod

@throws WatsonBridgeException
@return Bridge
778207
public function constructBridge($credential, $service = null, $authMethod = 'credentials')
    {
        // Get credentials array.
        $credentials = $this->getCredentials($credential);

        // Make sure credentials information is available.
        if (! isset($credentials['username']) || ! isset($credentials['password']) || ! isset($credentials['gateway'])) {
            throw new WatsonBridgeException('Could not construct Bridge, missing some information in credentials.',
                                            500);
        }

        // Make bridge.
        $bridge = $this->makeRawBridge()
                       ->setUsername($credentials['username'])
                       ->setPassword($credentials['password'])
                       ->setEndPoint($credentials['gateway'])
                       ->setClient($credentials['gateway'])
                       ->appendHeaders(['X-Watson-Learning-Opt-Out' => config('watson-bridge.x_watson_learning_opt_out')]);

        // Add service.
        $bridge = $this->addServiceToBridge($bridge, $service);

        // Choose an auth method.
        $bridge = $this->chooseAuthMethodForBridge($bridge, $authMethod);

        return $bridge;
    }
268708
public function usingService($serviceName)
    {
        // Check if service exists first.
        if (! config()->has('watson-bridge.services.'.$serviceName)) {
            throw new WatsonBridgeException('Unknown service "'.$serviceName.'" try adding it to the list of services in watson-bridge config.');
        }

        // Get service endpoint.
        $serviceUrl = config('watson-bridge.services.'.$serviceName);

        // Reset Client.
        $this->setClient(rtrim($this->endpoint, '/').'/'.ltrim($serviceUrl, '/'));

        return $this;
    }
938415
public static function wrap(
        callable $credentialProvider,
        $options,
        $region,
        $service
    ) {
        return function (callable $handler) use (
            $credentialProvider,
            $options,
            $region,
            $service
        ) {
            return new static(
                $handler,
                $credentialProvider,
                $options,
                $region,
                $service
            );
        };
    }
29890
private String signAndCreateAuthzHeader(String endpointUrl, Map<String, String> parameters) {

        String signature = computeSignature(requestMethod, endpointUrl, parameters);
        parameters.put(TwitterConstants.PARAM_OAUTH_SIGNATURE, signature);

        String authzHeaderString = createAuthorizationHeaderString(parameters);
        return authzHeaderString;
    }
32072
public function createNew(
        string $providerName,
        string $credentialPubKey,
        string $accessToken,
        string $tokenSecret = '',
        string $signupHash = ''
    ) : array {

        $array = [
            'provider'     => $providerName,
            'access_token' => $accessToken,
            'credential'   => $credentialPubKey
        ];

        if (! empty($tokenSecret)) {
            $array['token_secret'] = $tokenSecret;
        }

        if (! empty($signupHash)) {
            $array['signup_hash'] = $signupHash;
        }

        return $this->sendPost(
            '/sso',
            [],
            $array
        );
    }
1196501
public SdkClientBuilder proxyCredentials(String user, String password) {
        this.proxyCredentials = new UsernamePasswordCredentials(user, password);
        return this;
    }
29861
private Credential newCredential(String userId) {
        Credential.Builder builder = new Credential.Builder(getMethod())
                .setTransport(getTransport())
                .setJsonFactory(getJsonFactory())
                .setTokenServerEncodedUrl(getTokenServerEncodedUrl())
                .setClientAuthentication(getClientAuthentication())
                .setRequestInitializer(getRequestInitializer())
                .setClock(getClock());
        if (getCredentialStore() != null) {
            builder.addRefreshListener(
                    new CredentialStoreRefreshListener(userId, getCredentialStore()));
        }

        builder.getRefreshListeners().addAll(getRefreshListeners());

        return builder.build();
    }
934287
public static function create(
        AuthInterface $authentication,
        bool $throwsExceptions = false,
        string $baseUrl = 'https://api.idos.io/1.0/'
    ) : self {
        return new static(
            $authentication,
            new Client(),
            $throwsExceptions,
            $baseUrl
        );
    }
295440
@VisibleForTesting
    protected Function<Credential, GitHubServerConfig> toGHServerConfig() {
        return new Function<Credential, GitHubServerConfig>() {
            @Override
            public GitHubServerConfig apply(Credential input) {
                LOGGER.info("Migrate GitHub Plugin creds for {} {}", input.getUsername(), input.getApiUrl());
                GitHubTokenCredentialsCreator creator =
                        Jenkins.getInstance().getDescriptorByType(GitHubTokenCredentialsCreator.class);

                StandardCredentials credentials = creator.createCredentials(
                        input.getApiUrl(),
                        input.getOauthAccessToken(),
                        input.getUsername()
                );

                GitHubServerConfig gitHubServerConfig = new GitHubServerConfig(credentials.getId());
                gitHubServerConfig.setApiUrl(input.getApiUrl());

                return gitHubServerConfig;
            }
        };
    }
456586
private function createAuthenticationException(JWTDecodeFailureException $previous = null)
    {
        $message = (null === $previous) ? 'Invalid JWT Token' : $previous->getMessage();

        return new AuthenticationException($message, 401, $previous);
    }
1003878
@Override
    public SICoreConnection createConnection(ClientConnection cc,
                                             String credentialType, String userid, String password)
                    throws SIResourceException, SINotAuthorizedException,
                    SIAuthenticationException {

        if (TraceComponent.isAnyTracingEnabled()
            && CoreSPIConnFactory.tc.isEntryEnabled()) {
            SibTr.entry(CoreSPIConnFactory.tc, "createConnection",
                        new Object[] { cc, credentialType, userid, password });
        }

        // Check that the Messaging Engine is started
        checkStarted();

        if ("".equals(userid))
            userid = null;

        SICoreConnection connection = null;
        SSLSession sslSession = cc.getMetaData().getSSLSession();

        if (credentialType.equals(TrmConstantsImpl.CREDENTIAL_USERID_PASSWORD)) {
            Certificate[] peerCerts = null;
            // Get hold of SSL credentials if userID null
            if (userid == null) {
                if (sslSession != null) {
                    try {
                        // Attempt to get hold of peer certificates
                        if (TraceComponent.isAnyTracingEnabled()
                            && tc.isDebugEnabled())
                            SibTr.debug(tc,
                                        "Authentication: attempting to retrieve SSL Peer certificates");
                        peerCerts = sslSession.getPeerCertificates();
                    } catch (SSLPeerUnverifiedException sslPUE) {
                        // No FFDC Code Needed
                        // No action needed - this will be handled by the
                        // anonymous login section below
                        if (TraceComponent.isAnyTracingEnabled()
                            && tc.isDebugEnabled())
                            SibTr.debug(tc,
                                        "Authentication: Error obtaining SSL certificates >"
                                                        + sslPUE + "<");
                    }
                }
            }
            // Call login depending on credentials provided
            if (userid != null) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    SibTr.debug(tc,
                                "Authentication: Login using user ID and password");
                connection = createConnection(userid, password, null);
            } else if ((peerCerts != null) && (peerCerts.length > 0)) {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    SibTr.debug(tc,
                                "Authentication: Login using SSL Peer certificates");
                connection = createConnection(peerCerts);
            } else {
                if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled())
                    SibTr.debug(
                                tc,
                                "Authentication: Anonymous Login using user ID and password; note that these may be null");
                connection = createConnection(userid, password, null);
            }
        }

        //mark connection  type comms/commsssl. Explicitly porting connection to ConnectionImpl as all connection in MP are off type ConnectionImpl
        if (null != sslSession)
            ((ConnectionImpl) connection).setConnectionType(SIMPConstants.MP_VIACOMMSSSL_CONNECTION);
        else
            ((ConnectionImpl) connection).setConnectionType(SIMPConstants.MP_VIACOMMS_CONNECTION);

        if (TraceComponent.isAnyTracingEnabled()
            && CoreSPIConnFactory.tc.isEntryEnabled())
            SibTr.exit(CoreSPIConnFactory.tc, "createConnection", connection);
        return connection;
    }
850993
public Credential loadCredential(String userId) throws AuthException {
        try {
            return authorizationCodeFlow.loadCredential(userId);
        } catch (IOException e) {
            throw new AuthException("Unable to load credential.", e);
        }
    }
155196
public static AuthenticationBuilder newInstance(final Authentication source) {
        val builder = new DefaultAuthenticationBuilder(source.getPrincipal());
        builder.setAuthenticationDate(source.getAuthenticationDate());
        builder.setCredentials(source.getCredentials());
        builder.setSuccesses(source.getSuccesses());
        builder.setFailures(source.getFailures());
        builder.setAttributes(source.getAttributes());
        builder.setWarnings(source.getWarnings());
        return builder;
    }
1251356
private static AWSSecurityTokenService buildStsClient(Builder builder) throws
                                                                           IllegalArgumentException {
        /**
         * Passing two types of credential interfaces is not permitted
         */
        if (builder.longLivedCredentials != null && builder.longLivedCredentialsProvider != null) {
            throw new IllegalArgumentException(
                    "It is illegal to set both an AWSCredentials and an AWSCredentialsProvider for an " +
                    STSAssumeRoleSessionCredentialsProvider.class.getName());
        }

        AWSCredentialsProvider longLivedCredentialsProvider = null;
        if (builder.longLivedCredentials != null) {
            longLivedCredentialsProvider = new StaticCredentialsProvider(
                    builder.longLivedCredentials);
        } else if (builder.longLivedCredentialsProvider != null) {
            longLivedCredentialsProvider = builder.longLivedCredentialsProvider;
        }

        // Depending on which options are explicitly provided we have to call the right overloaded constructor so
        // defaults are properly applied.
        if (longLivedCredentialsProvider == null) {
            if (builder.clientConfiguration == null) {
                return new AWSSecurityTokenServiceClient();
            } else {
                return new AWSSecurityTokenServiceClient(builder.clientConfiguration);
            }
        } else {
            if (builder.clientConfiguration == null) {
                return new AWSSecurityTokenServiceClient(longLivedCredentialsProvider);
            } else {
                return new AWSSecurityTokenServiceClient(longLivedCredentialsProvider,
                                                         builder.clientConfiguration);
            }
        }
    }
1272973
private function _signHeader($endpoint, $authMethod, $params)
    {
        if (!is_array($params)) {
            $params = array();
        }
        if ($authMethod) {
            list($key, $value) = explode('=', substr($authMethod, 1), 2);
            $params[$key] = $value;
        }
        $baseString = '/' . $endpoint;
        ksort($params);
        foreach ($params as $key => $value) {
            $baseString .= '|' . $key . '=' . $value;
        }
        $signature = hash_hmac('sha256', $baseString, $this->_apisecret, false);

        return $signature;
    }
1324583
public function passValidateCredentialsAndCreateAccessTokenResponse(
        string $userName,
        string $password,
        ClientInterface $client = null,
        bool $isScopeModified = false,
        array $scope = null,
        array $extraParameters = []
    ): ResponseInterface {
        assert($client !== null);

        if (($userIdentifier = $this->getIntegration()->validateUserId($userName, $password)) === null) {
            $this->logDebug('User not found with provided username and password.', ['username' => $userName]);
            throw new OAuthTokenBodyException(OAuthTokenBodyException::ERROR_INVALID_GRANT);
        }
        assert(is_int($userIdentifier) === true);
        $this->logInfo('User authenticated with provided username and password.', ['username' => $userName]);

        $changedScopeOrNull = $this->getIntegration()->verifyAllowedUserScope($userIdentifier, $scope);
        if ($changedScopeOrNull !== null) {
            assert(is_array($changedScopeOrNull));
            $isScopeModified = true;
            $scope           = $changedScopeOrNull;
        }

        $unsavedToken = $this->getIntegration()->createTokenInstance();
        $unsavedToken
            ->setClientIdentifier($client->getIdentifier())
            ->setScopeIdentifiers($scope)
            ->setUserIdentifier($userIdentifier);
        $isScopeModified === true ? $unsavedToken->setScopeModified() : $unsavedToken->setScopeUnmodified();

        $tokenExpiresIn = $this->setUpTokenValues($unsavedToken);
        $savedToken     = $this->getIntegration()->getTokenRepository()->createToken($unsavedToken);

        $response = $this->createBodyTokenResponse($savedToken, $tokenExpiresIn);

        return $response;
    }
304342
public net.minidev.ovh.api.auth.OvhCredential credential_POST(OvhAccessRule[] accessRules, String redirection) throws IOException {
		String qPath = "/auth/credential";
		StringBuilder sb = path(qPath);
		HashMap<String, Object>o = new HashMap<String, Object>();
		addBody(o, "accessRules", accessRules);
		addBody(o, "redirection", redirection);
		String resp = execN(qPath, "POST", sb.toString(), o);
		return convertTo(resp, net.minidev.ovh.api.auth.OvhCredential.class);
	}