NOTE: For Version 3 of the AWS SDK for PHP, please see the V3 User Guide and V3 API Reference.

# Class Credentials

Basic implementation of the AWSCredentials interface that allows callers to pass in the AWS access key and secret access in the constructor.

  Aws\Common\Credentials\Credentials implements Aws\Common\Credentials\CredentialsInterface, Guzzle\Common\FromConfigInterface

Namespace: Aws\Common\Credentials
Located at Aws/Common/Credentials/Credentials.php

## Methods summary

- `public static` `getConfigDefaults ( )`

  Get the available keys for the factory method

- `public static` `factory ( array $config = array() )`

  Factory method for creating new credentials. This factory method will create the appropriate credentials object with appropriate decorators based on the passed configuration options.

- `public static` `fromIni ( string|null $profile = null, string|null $filename = null )`

  Create credentials from the credentials ini file in the HOME directory.

- `public` `__construct ( string $accessKeyId, string $secretAccessKey, string $token = null, int $expiration = null )`

  Constructs a new BasicAWSCredentials object, with the specified AWS access key and AWS secret key

- `public` `serialize ( )`
- `public` `unserialize ( mixed $serialized )`
- `public` `getAccessKeyId ( )`

  Returns the AWS access key ID for this credentials object.

- `public` `getSecretKey ( )`

  Returns the AWS secret access key for this credentials object.

- `public` `getSecurityToken ( )`

  Get the associated security token if available

- `public` `getExpiration ( )`

  Get the UNIX timestamp in which the credentials will expire

- `public` `isExpired ( )`

  Check if the credentials are expired

- `public` `setAccessKeyId ( string $key )`

  Set the AWS access key ID for this credentials object.

- `public` `setSecretKey ( string $secret )`

  Set the AWS secret access key for this credentials object.

- `public` `setSecurityToken ( string $token )`

  Set the security token to use with this credentials object

- `public` `setExpiration ( int $timestamp )`

  Set the UNIX timestamp in which the credentials will expire

## Methods detail

# `public static array`
`getConfigDefaults( )`

Get the available keys for the factory method

#### Returns

`array`
# `public static `Aws\Common\Credentials\CredentialsInterface``
`factory( array $config = array() )`

Factory method for creating new credentials. This factory method will create the appropriate credentials object with appropriate decorators based on the passed configuration options.

#### Parameters

$config
  `array`
  $config Options to use when instantiating the credentials

#### Returns

``Aws\Common\Credentials\CredentialsInterface``

#### Throws

``Aws\Common\Exception\InvalidArgumentException``
If the caching options are invalid
``Aws\Common\Exception\RuntimeException``
If using the default cache and APC is disabled

#### Implementation of

`Guzzle\Common\FromConfigInterface::factory()`
# `public static `Aws\Common\Credentials\CredentialsInterface``
`fromIni( string|null $profile = null, string|null $filename = null )`

Create credentials from the credentials ini file in the HOME directory.

#### Parameters

$profile
  `string|null`
  $profile Pass a specific profile to use. If no profile is specified we will attempt to use the value specified in the AWS_PROFILE environment variable. If AWS_PROFILE is not set, the "default" profile is used.
$filename
  `string|null`
  $filename Pass a string to specify the location of the credentials files. If null is passed, the SDK will attempt to find the configuration file at in your HOME directory at ~/.aws/credentials.

#### Returns

``Aws\Common\Credentials\CredentialsInterface``

#### Throws

``RuntimeException``
if the file cannot be found, if the file is invalid, or if the profile is invalid.
# `public`
`__construct( string $accessKeyId, string $secretAccessKey, string $token = null, integer $expiration = null )`

Constructs a new BasicAWSCredentials object, with the specified AWS access key and AWS secret key

#### Parameters

$accessKeyId
  `string`
  $accessKeyId AWS access key ID
$secretAccessKey
  `string`
  $secretAccessKey AWS secret access key
$token
  `string`
  $token Security token to use
$expiration
  `integer`
  $expiration UNIX timestamp for when credentials expire

# `public`
`serialize( )`

#### Implementation of

`Serializable::serialize()`
# `public`
`unserialize( mixed $serialized )`

#### Implementation of

`Serializable::unserialize()`
# `public string`
`getAccessKeyId( )`

Returns the AWS access key ID for this credentials object.

#### Returns

`string`

#### Implementation of

`Aws\Common\Credentials\CredentialsInterface::getAccessKeyId()`
# `public string`
`getSecretKey( )`

Returns the AWS secret access key for this credentials object.

#### Returns

`string`

#### Implementation of

`Aws\Common\Credentials\CredentialsInterface::getSecretKey()`
# `public string|null`
`getSecurityToken( )`

Get the associated security token if available

#### Returns

`string|null`

#### Implementation of

`Aws\Common\Credentials\CredentialsInterface::getSecurityToken()`
# `public integer|null`
`getExpiration( )`

Get the UNIX timestamp in which the credentials will expire

#### Returns

`integer|null`

#### Implementation of

`Aws\Common\Credentials\CredentialsInterface::getExpiration()`
# `public boolean`
`isExpired( )`

Check if the credentials are expired

#### Returns

`boolean`

#### Implementation of

`Aws\Common\Credentials\CredentialsInterface::isExpired()`
# `public `Aws\Common\Credentials\Credentials``
`setAccessKeyId( string $key )`

Set the AWS access key ID for this credentials object.

#### Parameters

$key
  `string`
  $key AWS access key ID

#### Returns

``Aws\Common\Credentials\Credentials``

#### Implementation of

`Aws\Common\Credentials\CredentialsInterface::setAccessKeyId()`
# `public `Aws\Common\Credentials\CredentialsInterface``
`setSecretKey( string $secret )`

Set the AWS secret access key for this credentials object.

#### Parameters

$secret
  `string`
  $secret AWS secret access key

#### Returns

``Aws\Common\Credentials\CredentialsInterface``

#### Implementation of

`Aws\Common\Credentials\CredentialsInterface::setSecretKey()`
# `public `Aws\Common\Credentials\Credentials``
`setSecurityToken( string $token )`

Set the security token to use with this credentials object

#### Parameters

$token
  `string`
  $token Security token

#### Returns

``Aws\Common\Credentials\Credentials``

#### Implementation of

`Aws\Common\Credentials\CredentialsInterface::setSecurityToken()`
# `public `Aws\Common\Credentials\Credentials``
`setExpiration( integer $timestamp )`

Set the UNIX timestamp in which the credentials will expire

#### Parameters

$timestamp
  `integer`
  $timestamp UNIX timestamp expiration

#### Returns

``Aws\Common\Credentials\Credentials``

#### Implementation of

`Aws\Common\Credentials\CredentialsInterface::setExpiration()`

### Magic methods summary

## Constants summary

`string` | `ENV_KEY` | `'AWS_ACCESS_KEY_ID'` | #
`string` | `ENV_SECRET` | `'AWS_SECRET_KEY'` | #
`string` | `ENV_SECRET_ACCESS_KEY` | `'AWS_SECRET_ACCESS_KEY'` | #
`string` | `ENV_PROFILE` | `'AWS_PROFILE'` | #

## Properties summary

`protected string` | $key | # AWS Access Key ID
`protected string` | $secret | # AWS Secret Access Key
`protected string` | $token | # AWS Security Token
`protected integer` | $ttd | # Time to die of token