Skip to content

Instantly share code, notes, and snippets.

@rbrayb
Created March 25, 2018 19:50
Show Gist options
  • Save rbrayb/7b3051b40c9988c009582f49eab457ac to your computer and use it in GitHub Desktop.
Save rbrayb/7b3051b40c9988c009582f49eab457ac to your computer and use it in GitHub Desktop.
ADFS Postman script to show UserInfo call
{
"variables": [],
"info": {
"name": "ADFS Public Gist",
"_postman_id": "98eded09-3ecd-7239-9cf4-a6da2c92809e",
"description": "Auth code flow.",
"schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
},
"item": [
{
"name": "Auth. Code Grant",
"description": "",
"item": [
{
"name": "Authorize Request",
"request": {
"url": "https://my-adfs/adfs/oauth2/authorize?client_id=526191a3-887c-42f8-a8ab-0d9232c669a9&response_type=code&redirect_uri=https%3A%2F%2Fmy-pc%2FADFS40TodoListWebApp%2F&response_mode=query&scope=openid",
"method": "GET",
"header": [],
"body": {
"mode": "raw",
"raw": ""
},
"description": "A sign in request to begin the OAuth 2.0 code flow. Be sure to copy & paste into a browser! Running this request in Postman will just return you the HTML of our login pages. You need to fill in your own tenant ID and clientID. You can get the tenant ID from the ADFS endpoints in the wizard. Running this will ask you for your AD credentials. Note that this will return a 'HTTP Error 404.0 - Not Found' because there is no 'localhost/myapp'. Just ignore and copy the code - the section after '?code=' "
},
"response": []
},
{
"name": "Token Request - Auth Code",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"tests['Status Code is 200'] = (responseCode.code === 200);",
"",
"if (responseCode.code === 200) {",
" ",
" try {",
" var tokens = JSON.parse(responseBody),",
" access_token = tokens.access_token;",
" }",
"",
" catch(e) {",
" console.log(e);",
" }",
" ",
" postman.setGlobalVariable(\"access_token\", access_token);",
"}"
]
}
}
],
"request": {
"url": "https://my-adfs/adfs/oauth2/token",
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/x-www-url-form-urlencoded",
"description": ""
}
],
"body": {
"mode": "urlencoded",
"urlencoded": [
{
"key": "client_id",
"value": "526191a3-887c-42f8-a8ab-0d9232c669a9",
"type": "text"
},
{
"key": "scope",
"value": "openid",
"type": "text"
},
{
"key": "redirect_uri",
"value": "https://my-pc/ADFS40TodoListWebApp/",
"type": "text"
},
{
"key": "grant_type",
"value": "authorization_code",
"type": "text"
},
{
"key": "client_secret",
"value": "vh8B2fO_GGx9yzmUe8xXfAmF6OdBWLKzctij4ADs",
"type": "text"
},
{
"key": "code",
"value": "-LMchRmB8k6I6Nh7lg7Uhw.LxKL0APH1AgLALQyL_k4feUVj7c.TdJS_8yDPhcP9nRviN08BXzpPwh9DGwE106VGPPPnDfsWpKydO_SyR8js28KEdeOC13H5kF7QSTJRZSBqvJKZKayv10XwaUQc7JlJfcmkm0wbB7i8S-dbifeeDxyEqPiF9QDVVsFkqohHyz5SnlEabsBhhA21y2iJgaENk_2ULEaNYA3TZFhLByxOjrcqpRF-OZPAGM0ujifMYqb7DOoU47oYBdctglbwGIBJNLxGqDJcsdttihq9nniUNx5xRR7vqdEz3e9Uvr2SOZm85P0TKum1di50NzcpE2NSCv_uMUk9THBlH010bwVT4QvMzWYzuEw-T1LfKaMACKoHf-DAg",
"type": "text"
}
]
},
"description": "The POST request to exchange an auth code for an access token. Be sure to replace the code with your own, that you received after signing in! Again you need to fill in your own client_id and client_secret. Then click 'Send'. This will return an access token, an ID token and a refresh token. You can see what's in the access / ID token by copy / paste into 'jwt.io' in a browser. "
},
"response": []
},
{
"name": "Userinfo Request",
"event": [
{
"listen": "test",
"script": {
"type": "text/javascript",
"exec": [
"tests['Status Code is 200'] = (responseCode.code === 200);",
""
]
}
}
],
"request": {
"url": "https://my-adfs/adfs/userinfo",
"method": "GET",
"header": [
{
"key": "Authorization",
"value": "Bearer {{access_token}}",
"description": ""
}
],
"body": {},
"description": "An example use of the access_token. Normally you would replace the access token with the one you got from the token request! This is done automatically. Just click 'Send'. You should get attributes like 'sub' back."
},
"response": []
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment