Skip to content

Instantly share code, notes, and snippets.

@dsolovay
Created January 4, 2023 03:48
Show Gist options
  • Save dsolovay/ea2f66b2b98582c4f314a0884cbba9df to your computer and use it in GitHub Desktop.
Save dsolovay/ea2f66b2b98582c4f314a0884cbba9df to your computer and use it in GitHub Desktop.
Get GraphQL Access token for Sitecore 10.3
<!-- NOTE: THIS IS A FRAGMENT. INCLUDE THIS IN Sitecore.IdentityServer.Host.xml, in node /Settings/Sitecore/IdentityServer/Clients -->
<!-- Postman configuration documented here: https://doc.sitecore.com/xp/en/developers/92/sitecore-experience-commerce/bearer-token-authentication.html -->
<PostmanClient>
<ClientId>postman-api</ClientId>
<ClientName>Postman API</ClientName>
<AccessTokenType>0</AccessTokenType>
<AllowOfflineAccess>true</AllowOfflineAccess>
<AlwaysIncludeUserClaimsInIdToken>false</AlwaysIncludeUserClaimsInIdToken>
<AccessTokenLifetimeInSeconds>3600</AccessTokenLifetimeInSeconds>
<IdentityTokenLifetimeInSeconds>3600</IdentityTokenLifetimeInSeconds>
<AllowAccessTokensViaBrowser>true</AllowAccessTokensViaBrowser>
<RequireConsent>false</RequireConsent>
<RequireClientSecret>false</RequireClientSecret>
<AllowedGrantTypes>
<AllowedGrantType1>password</AllowedGrantType1>
</AllowedGrantTypes>
<RedirectUris>
<RedirectUri1>{AllowedCorsOrigin}/oauth2/callback</RedirectUri1>
</RedirectUris>
<PostLogoutRedirectUris>
<PostLogoutRedirectUri1>{AllowedCorsOrigin}</PostLogoutRedirectUri1>
</PostLogoutRedirectUris>
<AllowedCorsOrigins>
<AllowedCorsOrigins1>https://www.getpostman.com</AllowedCorsOrigins1>
</AllowedCorsOrigins>
<AllowedScopes>
<!-- Scopes documented here: https://doc.sitecore.com/xp/en/developers/103/sitecore-experience-manager/use-bearer-tokens-in-client-applications.html -->
<AllowedScope1>openid</AllowedScope1>
<AllowedScope2>sitecore.profile</AllowedScope2>
<AllowedScope3>sitecore.profile.api</AllowedScope3>
</AllowedScopes>
<UpdateAccessTokenClaimsOnRefresh>true</UpdateAccessTokenClaimsOnRefresh>
</PostmanClient>
{
"info": {
"_postman_id": "d5816c17-9c4b-4a0f-8b78-beb5ea07e3ae",
"name": "Sitecore GraphQL",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "0"
},
"item": [
{
"name": "GetToken",
"event": [
{
"listen": "test",
"script": {
"exec": [
"var jsonData = JSON.parse(responseBody);",
"",
"postman.setGlobalVariable(\"SitecoreIdToken\", \"Bearer \" + jsonData.access_token);",
""
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/x-www-form-urlencoded"
},
{
"key": "Accept",
"value": "application/json"
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "password",
"value": "{{SitecoreIdServerPassword}}",
"type": "text"
},
{
"key": "grant_type",
"value": "password",
"type": "text"
},
{
"key": "username",
"value": "{{SitecoreIdServerUserName}}",
"type": "text"
},
{
"key": "client_id",
"value": "postman-api",
"type": "text"
},
{
"key": "scope",
"value": "openid sitecore.profile sitecore.profile.api",
"type": "text"
}
]
},
"url": {
"raw": "{{SitecoreIdServerHost}}/connect/token",
"host": [
"{{SitecoreIdServerHost}}"
],
"path": [
"connect",
"token"
]
}
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
""
]
}
}
],
"variable": [
{
"key": "SitecoreIdServerHost",
"value": "https://xp0identityserver.dev.local",
"type": "string"
},
{
"key": "SitecoreIdServerUserName",
"value": "sitecore\\admin",
"type": "string"
},
{
"key": "SitecoreIdServerPassword",
"value": "b",
"type": "string"
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment