azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

New-AzureRmADAppCredential: Key credential end date is invalid

Open PowershellNinja opened this issue 8 years ago • 11 comments

Description

I am trying to add a certificate credential to a fresh Azure AD App. Upon running New-AzureRmADAppCredential it tells me that the Key credential end date is invalid - unless I do a .AddDays(-1) on the EndDate DateTimeObject I provide to the Cmdlet. If I do that, everything works fine.

Noteable in the debug Output below is that the date formatting is the same in both cases:

Case .AddDays(-1) (Works) Body: { "value": [ { "startDate": "2018-08-08T15:18:27Z", "endDate": "2019-08-07T15:18:27Z",

Case just GetExpirationDateString() (Does not work) Body: { "value": [ { "startDate": "2018-08-08T15:18:27Z", "endDate": "2019-08-08T15:18:27Z",

Does it just somehow not like when the timespan between start and end date is longer than or exactly 1 year?

Script/Steps for Reproduction

$certificate = New-Object System.Security.Cryptography.X509Certificates.X509Certificate
$certificate.Import($publicKeyCrtPath)
$certBinaries = $certificate.GetRawCertData()
$encodedCert = [System.Convert]::ToBase64String($certBinaries)

$splat = @{
            ApplicationId = $azureADApplicationId
            CertValue = $encodedCert
            StartDate = Get-Date -Date $certificate.GetEffectiveDateString()
            EndDate = Get-Date -Date $certificate.GetExpirationDateString()
        }

        New-AzureRmADAppCredential @splat

Module Version

Get-Module -Name AzureRM -ListAvailable

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     6.7.0      AzureRM

Environment Data

$PSVersionTable
Name                           Value
----                           -----
PSVersion                      5.1.17134.228
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17134.228
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Debug Output

$DebugPreference = "Continue"
        $splat = @{
            ApplicationId = $azureADApplicationId
            CertValue = $encodedCert
            StartDate = Get-Date -Date $certificate.GetEffectiveDateString()
            EndDate = (Get-Date -Date $certificate.GetExpirationDateString())
        }

        New-AzureRmADAppCredential @splat

DEBUG: 14:28:55 - NewAzureADAppCredentialCommand begin processing with ParameterSet
'ApplicationIdWithCertValueParameterSet'.
DEBUG: 14:28:55 - using account id '[email protected]'...
DEBUG: [Common.Authentication]: Authenticating using Account: '[email protected]', environment: 'AzureCloud',
tenant: 'a97788c5-2cf8-4c88-bc98-c1e1842d75cb'
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 08/20/2018 12:28:55: 0cc197e9-c986-4c82-9186-f6233d7c5f2c - AcquireTokenHandlerBase: === Token Acquisition
started:
 Authority: https://login.microsoftonline.com/a97788c5-2cf8-4c88-bc98-c1e1842d75cb/
 Resource: https://graph.windows.net/
 ClientId: 1950a258-227b-4e31-a9cf-717495945fc2
 CacheType: Microsoft.Azure.Commands.Common.Authentication.ProtectedFileTokenCache (3 items)
 Authentication Target: User

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 08/20/2018 12:28:55:  - TokenCache: Deserialized 3 items to token cache.
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 :
DEBUG: 08/20/2018 12:28:55: 0cc197e9-c986-4c82-9186-f6233d7c5f2c - TokenCache: Looking up cache for a token...
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 08/20/2018 12:28:55: 0cc197e9-c986-4c82-9186-f6233d7c5f2c - TokenCache: An item matching the requested resource
was found in the cache
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 :
DEBUG: 08/20/2018 12:28:55: 0cc197e9-c986-4c82-9186-f6233d7c5f2c - TokenCache: 20.363067485 minutes left until token in
 cache expires
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 08/20/2018 12:28:55: 0cc197e9-c986-4c82-9186-f6233d7c5f2c - TokenCache: A matching item (access token or refresh
 token or both) was found in the cache
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 08/20/2018 12:28:55: 0cc197e9-c986-4c82-9186-f6233d7c5f2c - AcquireTokenHandlerBase: === Token Acquisition
finished successfully. An access token was retuned:
 Access Token Hash: JUNa2Z+QBwodccH9W66ngrPQ3eDBTxUJT9JCjRax984=
 Refresh Token Hash: 4YwLnQBFjzHze1DkmK+yaCIRE3SzCbBstX0xw8OJEfo=
 Expiration Time: 08/20/2018 12:49:17 +00:00
 User Hash: bLrTlcQBqc/JP9Ybh2yb4WtIvm7/MIrO6IjXNrw8Kxg=

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 08/20/2018 12:28:55: bcdafdc2-f98e-47a3-a4dc-fb65005e0198 - AcquireTokenHandlerBase: === Token Acquisition
started:
 Authority: https://login.microsoftonline.com/a97788c5-2cf8-4c88-bc98-c1e1842d75cb/
 Resource: https://graph.windows.net/
 ClientId: 1950a258-227b-4e31-a9cf-717495945fc2
 CacheType: Microsoft.Azure.Commands.Common.Authentication.ProtectedFileTokenCache (3 items)
 Authentication Target: User

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 08/20/2018 12:28:55:  - TokenCache: Deserialized 3 items to token cache.
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 :
DEBUG: 08/20/2018 12:28:55: bcdafdc2-f98e-47a3-a4dc-fb65005e0198 - TokenCache: Looking up cache for a token...
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 08/20/2018 12:28:55: bcdafdc2-f98e-47a3-a4dc-fb65005e0198 - TokenCache: An item matching the requested resource
was found in the cache
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 :
DEBUG: 08/20/2018 12:28:55: bcdafdc2-f98e-47a3-a4dc-fb65005e0198 - TokenCache: 20.363067485 minutes left until token in
 cache expires
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 08/20/2018 12:28:55: bcdafdc2-f98e-47a3-a4dc-fb65005e0198 - TokenCache: A matching item (access token or refresh
 token or both) was found in the cache
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 08/20/2018 12:28:55: bcdafdc2-f98e-47a3-a4dc-fb65005e0198 - AcquireTokenHandlerBase: === Token Acquisition
finished successfully. An access token was retuned:
 Access Token Hash: JUNa2Z+QBwodccH9W66ngrPQ3eDBTxUJT9JCjRax984=
 Refresh Token Hash: 4YwLnQBFjzHze1DkmK+yaCIRE3SzCbBstX0xw8OJEfo=
 Expiration Time: 08/20/2018 12:49:17 +00:00
 User Hash: bLrTlcQBqc/JP9Ybh2yb4WtIvm7/MIrO6IjXNrw8Kxg=

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://graph.windows.net/a97788c5-2cf8-4c88-bc98-c1e1842d75cb/applications?$filter=appId eq
'f6a0a249-ed31-4dbd-bf1c-56bbeac41d45'&api-version=1.6

Headers:
x-ms-client-request-id        : 918b6776-7585-4114-ac37-3cbed30f2913
accept-language               : en-US

Body:


DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Pragma                        : no-cache
ocp-aad-diagnostics-server-name: HuLV3m92Gq2GMhv+pUmQLlhksq05FelFoEjIOi3ley4=
request-id                    : 1d44b841-811d-4e6c-9f70-ee0cfce7ea91
client-request-id             : a0054420-de3a-4a11-aa36-72cf9e292303
x-ms-dirapi-data-contract-version: 1.6
ocp-aad-session-key           :
w-zYZr4lPLglCnysop9STbt9OMC6m7340oDZgx6wgkVZ1teoL-h95V-K0KjSSSx9hRswwHTAxANzmV2DPlYt6qA5tWb5Doo-yNashZDjBhuP_5tNXtd7oKp
Mdh6H5MqPLhxewU0Mapzdg_MZccAcrA.vxC8FA3I4vx_ey2-JM2Kevu3jN4yYBxAwLvUOKBY-DY
X-Content-Type-Options        : nosniff
DataServiceVersion            : 3.0;
Strict-Transport-Security     : max-age=31536000; includeSubDomains
Access-Control-Allow-Origin   : *
Duration                      : 708035
Cache-Control                 : no-cache
Date                          : Mon, 20 Aug 2018 12:28:55 GMT
Server                        : Microsoft-IIS/10.0
X-AspNet-Version              : 4.0.30319
X-Powered-By                  : ASP.NET

Body:
{
  "odata.metadata":
"https://graph.windows.net/a97788c5-2cf8-4c88-bc98-c1e1842d75cb/$metadata#directoryObjects/Microsoft.DirectoryServices.
Application",
  "value": [
    {
      "odata.type": "Microsoft.DirectoryServices.Application",
      "objectType": "Application",
      "objectId": "601aecd7-dfb0-4b78-b778-a51321731954",
      "deletionTimestamp": null,
      "acceptMappedClaims": null,
      "addIns": [],
      "appId": "f6a0a249-ed31-4dbd-bf1c-56bbeac41d45",
      "appRoles": [],
      "availableToOtherTenants": false,
      "displayName": "SomeTestApp",
      "errorUrl": null,
      "groupMembershipClaims": null,
      "homepage": "https://whatever.com",
      "identifierUris": [
        "https://raphaelfaehhotmail.onmicrosoft.com/89eac175-631a-4dc4-b581-8997d7a647a2"
      ],
      "informationalUrls": {
        "termsOfService": null,
        "support": null,
        "privacy": null,
        "marketing": null
      },
      "isDeviceOnlyAuthSupported": null,
      "keyCredentials": [],
      "knownClientApplications": [],
      "logoutUrl": null,
      "logoUrl": null,
      "oauth2AllowIdTokenImplicitFlow": true,
      "oauth2AllowImplicitFlow": false,
      "oauth2AllowUrlPathMatching": false,
      "oauth2Permissions": [
        {
          "adminConsentDescription": "Allow the application to access SomeTestApp on behalf of the signed-in
user.",
          "adminConsentDisplayName": "Access SomeTestApp",
          "id": "a72aaa62-cb63-49f8-94fe-8cb78a6aaf3e",
          "isEnabled": true,
          "type": "User",
          "userConsentDescription": "Allow the application to access SomeTestApp on your behalf.",
          "userConsentDisplayName": "Access SomeTestApp",
          "value": "user_impersonation"
        }
      ],
      "oauth2RequirePostResponse": false,
      "optionalClaims": null,
      "orgRestrictions": [],
      "parentalControlSettings": {
        "countriesBlockedForMinors": [],
        "legalAgeGroupRule": "Allow"
      },
      "passwordCredentials": [],
      "publicClient": false,
      "publisherDomain": null,
      "recordConsentConditions": null,
      "replyUrls": [
        "https://whatever.com"
      ],
      "requiredResourceAccess": [
        {
          "resourceAppId": "00000002-0000-0000-c000-000000000000",
          "resourceAccess": [
            {
              "id": "311a71cc-e848-46a1-bdf8-97ff7156d8e6",
              "type": "Scope"
            }
          ]
        }
      ],
      "samlMetadataUrl": null,
      "signInAudience": "AzureADMyOrg",
      "tokenEncryptionKeyId": null
    }
  ]
}

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 08/20/2018 12:28:56: 948e12f6-8238-4e29-a186-c4e60b27a8fb - AcquireTokenHandlerBase: === Token Acquisition
started:
 Authority: https://login.microsoftonline.com/a97788c5-2cf8-4c88-bc98-c1e1842d75cb/
 Resource: https://graph.windows.net/
 ClientId: 1950a258-227b-4e31-a9cf-717495945fc2
 CacheType: Microsoft.Azure.Commands.Common.Authentication.ProtectedFileTokenCache (3 items)
 Authentication Target: User

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 08/20/2018 12:28:56:  - TokenCache: Deserialized 3 items to token cache.
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 :
DEBUG: 08/20/2018 12:28:56: 948e12f6-8238-4e29-a186-c4e60b27a8fb - TokenCache: Looking up cache for a token...
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 08/20/2018 12:28:56: 948e12f6-8238-4e29-a186-c4e60b27a8fb - TokenCache: An item matching the requested resource
was found in the cache
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 :
DEBUG: 08/20/2018 12:28:56: 948e12f6-8238-4e29-a186-c4e60b27a8fb - TokenCache: 20.3585714283333 minutes left until
token in cache expires
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 08/20/2018 12:28:56: 948e12f6-8238-4e29-a186-c4e60b27a8fb - TokenCache: A matching item (access token or refresh
 token or both) was found in the cache
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 08/20/2018 12:28:56: 948e12f6-8238-4e29-a186-c4e60b27a8fb - AcquireTokenHandlerBase: === Token Acquisition
finished successfully. An access token was retuned:
 Access Token Hash: JUNa2Z+QBwodccH9W66ngrPQ3eDBTxUJT9JCjRax984=
 Refresh Token Hash: 4YwLnQBFjzHze1DkmK+yaCIRE3SzCbBstX0xw8OJEfo=
 Expiration Time: 08/20/2018 12:49:17 +00:00
 User Hash: bLrTlcQBqc/JP9Ybh2yb4WtIvm7/MIrO6IjXNrw8Kxg=

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://graph.windows.net/a97788c5-2cf8-4c88-bc98-c1e1842d75cb/applications/601aecd7-dfb0-4b78-b778-a51321731954/keyCre
dentials?api-version=1.6

Headers:
x-ms-client-request-id        : 2bcfb2e6-4c18-4a13-aa91-f1b30985f1f9
accept-language               : en-US

Body:


DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Pragma                        : no-cache
ocp-aad-diagnostics-server-name: ifPIyt9vMCnKFyaKE4lcH5zgIpClhShv+gOgypPBJB8=
request-id                    : c8157367-6ed8-48f0-ac48-560630ad906b
client-request-id             : b8a0cdcf-e5e5-4415-a89d-648569c80e3e
x-ms-dirapi-data-contract-version: 1.6
ocp-aad-session-key           :
aZPxbCZ4fNEaYZuspV0mkS705-PHRyVKF49TMwaY0QeJH_6RMWXQW-OPpZsPBdUe02aMJAA3NtfoJDXokQ9hfMLaEwcl5nQbG4w7OxD02UomrgE2rEuT22V
8dvV-kEEke6EQbjemgDJGf-_tK12DSg.K3XXEW5GvVE2nbpuvfgnX4G2yawE6SXKYE942qPS1Hs
X-Content-Type-Options        : nosniff
DataServiceVersion            : 3.0;
Strict-Transport-Security     : max-age=31536000; includeSubDomains
Access-Control-Allow-Origin   : *
Duration                      : 493109
Cache-Control                 : no-cache
Date                          : Mon, 20 Aug 2018 12:28:55 GMT
Server                        : Microsoft-IIS/10.0
X-AspNet-Version              : 4.0.30319
X-Powered-By                  : ASP.NET

Body:
{
  "odata.metadata":
"https://graph.windows.net/a97788c5-2cf8-4c88-bc98-c1e1842d75cb/$metadata#Collection(Microsoft.DirectoryServices.KeyCre
dential)",
  "value": []
}

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 08/20/2018 12:28:56: 881d01c4-0a83-4c44-8bda-ec180a7d1742 - AcquireTokenHandlerBase: === Token Acquisition
started:
 Authority: https://login.microsoftonline.com/a97788c5-2cf8-4c88-bc98-c1e1842d75cb/
 Resource: https://graph.windows.net/
 ClientId: 1950a258-227b-4e31-a9cf-717495945fc2
 CacheType: Microsoft.Azure.Commands.Common.Authentication.ProtectedFileTokenCache (3 items)
 Authentication Target: User

DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 08/20/2018 12:28:56:  - TokenCache: Deserialized 3 items to token cache.
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 :
DEBUG: 08/20/2018 12:28:56: 881d01c4-0a83-4c44-8bda-ec180a7d1742 - TokenCache: Looking up cache for a token...
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 08/20/2018 12:28:56: 881d01c4-0a83-4c44-8bda-ec180a7d1742 - TokenCache: An item matching the requested resource
was found in the cache
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Verbose: 1 :
DEBUG: 08/20/2018 12:28:56: 881d01c4-0a83-4c44-8bda-ec180a7d1742 - TokenCache: 20.3566395716667 minutes left until
token in cache expires
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 08/20/2018 12:28:56: 881d01c4-0a83-4c44-8bda-ec180a7d1742 - TokenCache: A matching item (access token or refresh
 token or both) was found in the cache
DEBUG: Microsoft.IdentityModel.Clients.ActiveDirectory Information: 2 :
DEBUG: 08/20/2018 12:28:56: 881d01c4-0a83-4c44-8bda-ec180a7d1742 - AcquireTokenHandlerBase: === Token Acquisition
finished successfully. An access token was retuned:
 Access Token Hash: JUNa2Z+QBwodccH9W66ngrPQ3eDBTxUJT9JCjRax984=
 Refresh Token Hash: 4YwLnQBFjzHze1DkmK+yaCIRE3SzCbBstX0xw8OJEfo=
 Expiration Time: 08/20/2018 12:49:17 +00:00
 User Hash: bLrTlcQBqc/JP9Ybh2yb4WtIvm7/MIrO6IjXNrw8Kxg=

DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
PATCH

Absolute Uri:
https://graph.windows.net/a97788c5-2cf8-4c88-bc98-c1e1842d75cb/applications/601aecd7-dfb0-4b78-b778-a51321731954/keyCre
dentials?api-version=1.6

Headers:
x-ms-client-request-id        : a03710a9-eef4-4cc4-b6ec-da76373e09e2
accept-language               : en-US

Body:
{
  "value": [
    {
      "startDate": "2018-08-08T15:18:27Z",
      "endDate": "2019-08-08T15:18:27Z",
      "value":
"MIIH5jCCBc6gAwIBAgITQgAAFNFBmGjMlQ40AQAAAAAU0TANBgkqhkiG9w0BAQUFADBFMRMwEQYKCZImiZPyLGQBGRYDY29tMRcwFQYKCZImiZPyLGQBGR
YHbGVpc3RlcjEVMBMGA1UEAxMMTGVpc3RlckVudENBMB4XDTE4MDgwODEzMTgyN1oXDTE5MDgwODEzMTgyN1owcTELMAkGA1UEBhMCQ0gxCzAJBgNVBAgTA
k9XMQ8wDQYDVQQHEwZTYXJuZW4xEzARBgNVBAoTCkxlaXN0ZXIgQUcxCzAJBgNVBAsTAklUMSIwIAYDVQQDExlBenVyZUFELUFQUC1PMzY1LVNpdGVQcm92
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA55uMAPPJbmsDIhnk1o7UJCg36bP5ddFS66qFQ5WrHSLdPXJTeMCceUbnd6erLRxLNZXXsgsTkwR
DC6fqEIjEQxIzp2w8mg7w+EjukaWKl5+Fv4UM3x8r0hlASBtEXWJjGbtOZpbajWkdB/3b5BGeAOg/bUh9AZ31vRTupCvYD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q2oMSyD5zm3y/ZJcAxUrhl7nRVQ==",
      "keyId": "54c9af7e-5d28-45cd-827b-7f61586d5665",
      "usage": "Verify",
      "type": "AsymmetricX509Cert"
    }
  ]
}

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
BadRequest

Headers:
ocp-aad-diagnostics-server-name: 1m1rN1QYF5U9KeN4rZR6EVneAE1LvUXdGsPpOkbAINI=
request-id                    : 100ac9d3-049b-45e8-99fe-41b6602ef89d
client-request-id             : 38f3da4b-6308-4a2e-9dbf-af061043a396
x-ms-dirapi-data-contract-version: 1.6
ocp-aad-session-key           :
ive07XixQVJsbvdh_5f6FJdIS6UT-FcBKZEePUy2aRErmh-CRWEKUmwdnKyyyKjeTzb8xqSs7dc2nJbfXEeTVtAhBi6Stob3RJJt6s8h0StsxVVdnYll1M_
sqcWdVb-kxARzcQgu1ooCQI3_xBLMJw.sMajPGIvscR92popVMBk5V7NH5QIS_pCzi6lcR8WyiE
Strict-Transport-Security     : max-age=31536000; includeSubDomains
Access-Control-Allow-Origin   : *
Duration                      : 1033732
Cache-Control                 : private
Date                          : Mon, 20 Aug 2018 12:28:55 GMT
Server                        : Microsoft-IIS/10.0
X-AspNet-Version              : 4.0.30319
X-Powered-By                  : ASP.NET

Body:
{
  "odata.error": {
    "code": "Request_BadRequest",
    "message": {
      "lang": "en",
      "value": "Key credential end date is invalid."
    },
    "date": "2018-08-20T12:28:55",
    "requestId": "100ac9d3-049b-45e8-99fe-41b6602ef89d",
    "values": [
      {
        "item": "PropertyName",
        "value": "None"
      },
      {
        "item": "PropertyErrorCode",
        "value": "InvalidKeyEndDate"
      }
    ]
  }
}

DEBUG: Caught exception, type: Microsoft.Azure.Graph.RBAC.Version1_6.Models.GraphErrorException
New-AzureRmADAppCredential : Key credential end date is invalid.
In Zeile:13 Zeichen:9
+         New-AzureRmADAppCredential @splat
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [New-AzureRmADAppCredential], Exception
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.ActiveDirectory.NewAzureADAppCredentialCommand

PowershellNinja avatar Aug 20 '18 12:08 PowershellNinja

@darshanhs90 Can you take a look?

markcowl avatar Aug 21 '18 21:08 markcowl

I've tried multiple different ways of repro-ing this error, and I haven't seen anything. There is definitely no '1-year limit'. I used your code and got this error: "New-AzureRmADAppCredential : Key credential start date is invalid." The start date is invalid when the effective date < current time. Start date must be at least the present time.

Could you provide more details re: the end date invalid? Has this been a recurring problem?

grlin avatar Dec 06 '18 00:12 grlin

Yes it still occurs and seems related to the running OS culture settings, although we were not able to find a consistent behaviour. It occurs reproducably on machines that were installed with de-CH as culture, but sometimes (and thats were it gets strange) also on machines that were installed en-US and then changed the culture to de-CH - but not on all. My guess would be that the problem is related to the way the different cultures (os basis and added language packs) affect the date formatting internally after they have been provided to the Cmdlet

PowershellNinja avatar Dec 06 '18 07:12 PowershellNinja

If that's the case, could you record the full DateTime object the next time it fails? both the StartDate, EndDate, and the expiration/effective dates from the cert.

grlin avatar Dec 06 '18 19:12 grlin

isn't this fixed already - https://github.com/Azure/azure-powershell/issues/7700

abhi1509 avatar Dec 16 '18 07:12 abhi1509

As far as I can tell this is a different issue. However, I fixed part of the cmdlet that may have contributed. In short, sometimes the cmdlet couldn't identify when an End Date was set, and was therefore setting it to some default.

grlin avatar Dec 17 '18 17:12 grlin

@PowershellNinja do you still see this issue when using Az 1.0?

grlin avatar Jan 09 '19 19:01 grlin

Thanks for this! Doing:

$validTo = [datetime]::Parse($pfx.GetExpirationDateString())
# Magic fix:
$validTo = $validTo.AddDays(-1);

does make New-AzureADApplicationKeyCredential work.

HQJaTu avatar Feb 11 '19 13:02 HQJaTu

This seems to be a time zone issue. My new code is:

$validTo = [datetime]::Parse($pfx.GetExpirationDateString())
$validTo = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId($validTo, [System.TimeZoneInfo]::Local.Id, 'GMT Standard Time')

Going for GMT makes validity work as certificate information states. My Windows is running GMT+2 making certificate validity two hours off.

HQJaTu avatar Feb 13 '19 07:02 HQJaTu

Hi! thanks for the update, I'll pass that info on to others seeing the same issue.

grlin avatar Feb 13 '19 18:02 grlin

$ThumbPrint = $RootCert.Thumbprint

$EndDate = $RootCert.NotAfter #(was causing the Key credential end date is invalid error)

$StartDate = $RootCert.NotBefore #(was causing the Key credential end date is invalid error)

$StartDate = [System.DateTime]::Now #(was causing the Key credential end date is invalid error)

$EndDate = $StartDate.AddYears(1) #(was causing the Key credential end date is invalid error)

$StartDate = [datetime]::Parse($RootCert.GetEffectiveDateString()) #(no MORE the Key credential end date is invalid error) $StartDate = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId($StartDate, [System.TimeZoneInfo]::Local.Id, 'GMT Standard Time') #(no MORE the Key credential end date is invalid error)

$EndDate = [datetime]::Parse($RootCert.GetExpirationDateString()) #(no MORE the Key credential end date is invalid error) $EndDate = [System.TimeZoneInfo]::ConvertTimeBySystemTimeZoneId($EndDate, [System.TimeZoneInfo]::Local.Id, 'GMT Standard Time') #(no MORE the Key credential end date is invalid error)

$CertValue = [System.Convert]::ToBase64String($RootCert.GetRawCertData())

$generateNewAzADServicePrincipal_AppSplat = @{ AppDisplayname = $AppDisplayname StartDate = $StartDate EndDate = $EndDate CertValue = $CertValue }

Generate-NewAzADServicePrincipal_App @generateNewAzADServicePrincipal_AppSplat

aollivierre avatar Dec 03 '20 14:12 aollivierre