On this page
Authentication is the only part of the Infinn API with any real subtlety. Once you hold an access token, every other call is the same shape.
- You send the user to an Infinn login page.
- They sign in; Infinn sends them back to you with a one-time code.
- You swap that code - plus a fingerprint proving you know your secret key - for an access token.
- You put the token on every later request.
The code is like a cloakroom ticket: it is useless on its own, works once, and is exchanged for the thing you actually want.
The flow
Step 1 - Send the user to the login page
Open this URL in a browser.
https://api.infinn.in/OAuthlogin/investor-entry-level/login?api_key=<API_KEY>&route_to=<ROUTE_TO>
# Example (API key IN001_U):
https://api.infinn.in/OAuthlogin/investor-entry-level/login?api_key=IN001_U&route_to=f63c3a3a696392e444acc5b708e13b74a5eaf04d580758d3e11eebf8c748c43aroute_to is not the API key. It is the SHA-256 hash (lower-case hex) of your user ID in capitals, a | character, and your API secret: route_to = sha256(USER_ID + "|" + SECRET_KEY). Example: user IN001, secret demo-secret-0000 gives f63c3a3a696392e444acc5b708e13b74a5eaf04d580758d3e11eebf8c748c43a. api_key stays your API key.
| Part | Value | Notes |
|---|---|---|
| Host and path | https://api.infinn.in/OAuthlogin/investor-entry-level/login | The same host as the API itself. |
api_key | <API_KEY> | From the profile icon → Generate Key (App Key). Not your user ID or client ID. |
route_to | <ROUTE_TO> | sha256(USER_ID + "|" + SECRET_KEY), lower-case hex. Not the API key. |
For your own first token there is no need to build a redirect flow at all. Paste the URL into a browser, log in, and copy the code out of the address bar. Build the redirect handling when you have real users.
Step 2 - Collect the one-time code
After a successful login the browser is redirected, and the URL carries a code parameter. The page itself will probably fail to load - that is expected and does not matter. Only the URL does.
?code=. The page not loading is normal.- It is 36 characters with dashes, in the shape
7a1c0e52-90b4-4f3d-a6e8-5d2c4b1f0a93. - It works exactly once. A failed exchange burns it, so a mistyped checksum means logging in again - not retrying.
- It is short-lived. Exchange it immediately.
Step 3 - Compute the checksum
The checksum proves you know your secret key without ever transmitting it. It is the SHA-256 hash of three values joined together with nothing in between:
The GenAcsTok reference page has a calculator that computes the checksum in your browser and gives you a copy button. Nothing is sent anywhere.
Use that for your first token. The code below is for when you are automating the login as part of a real system.
app_key + secret_key + codeThe API specification gives a worked example worth checking your code against. If the app key is IN001_U, the secret key is demo-secret-0000 and the code is 7a1c0e52-90b4-4f3d-a6e8-5d2c4b1f0a93, then you hash the string IN001_Udemo-secret-00007a1c0e52-90b4-4f3d-a6e8-5d2c4b1f0a93 - and nothing else.
Output the digest as lower-case hexadecimal. Getting this wrong is the single most common cause of Invalid Input : INVALID_VERIFIER.
import hashlib
import os
APP_KEY = os.environ["INFINN_API_KEY"]
SECRET_KEY = os.environ["INFINN_SECRET_KEY"]
CODE = "7a1c0e52-90b4-4f3d-a6e8-5d2c4b1f0a93" # from the redirect URL
checksum = hashlib.sha256(
(APP_KEY + SECRET_KEY + CODE).encode("utf-8")
).hexdigest()
print(checksum) # 64 lower-case hex characters// Node 16+ -- crypto is built in.
const crypto = require('crypto');
const APP_KEY = process.env.INFINN_API_KEY;
const SECRET_KEY = process.env.INFINN_SECRET_KEY;
const CODE = '7a1c0e52-90b4-4f3d-a6e8-5d2c4b1f0a93'; // from the redirect URL
const checksum = crypto
.createHash('sha256')
.update(APP_KEY + SECRET_KEY + CODE, 'utf8')
.digest('hex');
console.log(checksum); // 64 lower-case hex characters# Note: printf, not echo -- echo appends a newline, which changes the hash.
APP_KEY="your_app_key"
SECRET_KEY="your_secret_key"
CODE="7a1c0e52-90b4-4f3d-a6e8-5d2c4b1f0a93"
printf '%s' "${APP_KEY}${SECRET_KEY}${CODE}" | sha256sum | cut -d' ' -f1using System;
using System.Security.Cryptography;
using System.Text;
var apiKey = Environment.GetEnvironmentVariable("INFINN_API_KEY");
var secretKey = Environment.GetEnvironmentVariable("INFINN_SECRET_KEY");
var code = "7a1c0e52-90b4-4f3d-a6e8-5d2c4b1f0a93";
var bytes = SHA256.HashData(Encoding.UTF8.GetBytes(apiKey + secretKey + code));
var checksum = Convert.ToHexString(bytes).ToLowerInvariant();
Console.WriteLine(checksum);import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
public class Checksum {
public static void main(String[] args) throws Exception {
String apiKey = System.getenv("INFINN_API_KEY");
String secretKey = System.getenv("INFINN_SECRET_KEY");
String code = "7a1c0e52-90b4-4f3d-a6e8-5d2c4b1f0a93";
byte[] digest = MessageDigest.getInstance("SHA-256")
.digest((apiKey + secretKey + code).getBytes(StandardCharsets.UTF_8));
StringBuilder hex = new StringBuilder();
for (byte b : digest) hex.append(String.format("%02x", b));
System.out.println(hex);
}
}<?php
$apiKey = getenv('INFINN_API_KEY');
$secretKey = getenv('INFINN_SECRET_KEY');
$code = '7a1c0e52-90b4-4f3d-a6e8-5d2c4b1f0a93';
// hash() returns lower-case hex by default, which is what Infinn expects.
$checksum = hash('sha256', $apiKey . $secretKey . $code);
echo $checksum, PHP_EOL;Step 4 - Exchange the code for a token
This is the one endpoint that needs no Authorization header - it is the call that produces one.
POST /NorenWClientAPI/GenAcsTok HTTP/1.1
Host: api.infinn.in
Content-Type: text/plain
jData={"code":"7a1c0e52-90b4-4f3d-a6e8-5d2c4b1f0a93","checksum":"c5f9e053..."}{
"request_time": "20:18:47 19-05-2020",
"stat": "Ok",
"access_token": "dde92200b0744defa1d98e3b3cc0027530c6b31627619dd318c9e3cd88ecd33a",
"expires_in": "1756990407",
"refresh_token": "5e48d5f406a695014e934f601d0fe2bc9deb4b5800368d5927084d865660e2d9",
"lastaccesstime": "1589897972"
}Full field tables and all six language samples are on the Generate Access Token reference page.
A complete, runnable login
For automation. This does steps 3 and 4 in one go - computes the checksum, exchanges the code, prints the token - so a scheduled job can run it each morning without anyone visiting a page.
If you just want to try the API, use the in-page calculator instead. You only need a script like this once you are building something that logs in on its own.
Set two environment variables, pass the code as an argument, run it.
"""Exchange an Infinn login code for an access token.
Requires: pip install requests
export INFINN_API_KEY=...
export INFINN_SECRET_KEY=...
python login.py 7a1c0e52-90b4-4f3d-a6e8-5d2c4b1f0a93
"""
import hashlib
import json
import os
import sys
import requests
APP_KEY = os.environ["INFINN_API_KEY"]
SECRET_KEY = os.environ["INFINN_SECRET_KEY"]
CODE = sys.argv[1] if len(sys.argv) > 1 else input("Paste the code: ").strip()
# The code may be pasted as the whole redirect URL; take just the parameter.
if "code=" in CODE:
CODE = CODE.split("code=", 1)[1].split("&", 1)[0]
checksum = hashlib.sha256(
(APP_KEY + SECRET_KEY + CODE).encode("utf-8")
).hexdigest()
response = requests.post(
"https://api.infinn.in/NorenWClientAPI/GenAcsTok",
headers={"Content-Type": "text/plain"},
data="jData=" + json.dumps({"code": CODE, "checksum": checksum}),
timeout=10,
)
response.raise_for_status()
data = response.json()
if data.get("stat") != "Ok":
# A spent or expired code gives INVALID_VERIFIER. Log in again for a
# fresh one -- retrying with the same code cannot work.
raise SystemExit("Login failed: %s" % data.get("emsg", data))
print("access_token:", data["access_token"])
print("expires_in: ", data.get("expires_in"))/**
* Exchange an Infinn login code for an access token.
* Node 18+ (global fetch) -- no dependencies.
*
* INFINN_API_KEY=... INFINN_SECRET_KEY=... node login.js <code>
*/
const crypto = require('crypto');
const APP_KEY = process.env.INFINN_API_KEY;
const SECRET_KEY = process.env.INFINN_SECRET_KEY;
let code = process.argv[2];
if (!APP_KEY || !SECRET_KEY || !code) {
console.error('Set INFINN_API_KEY and INFINN_SECRET_KEY, and pass the code.');
process.exit(1);
}
// Accept either the bare code or the whole redirect URL.
if (code.includes('code=')) {
code = code.split('code=')[1].split('&')[0];
}
const checksum = crypto
.createHash('sha256')
.update(APP_KEY + SECRET_KEY + code, 'utf8')
.digest('hex');
async function main() {
const response = await fetch(
'https://api.infinn.in/NorenWClientAPI/GenAcsTok',
{
method: 'POST',
headers: { 'Content-Type': 'text/plain' },
body: 'jData=' + JSON.stringify({ code, checksum }),
},
);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const data = await response.json();
if (data.stat !== 'Ok') {
throw new Error(`Login failed: ${data.emsg || JSON.stringify(data)}`);
}
console.log('access_token:', data.access_token);
console.log('expires_in: ', data.expires_in);
}
main().catch((err) => {
console.error(err.message);
process.exit(1);
});Step 5 - Use the token
Put it in an Authorization header on every subsequent call. The scheme word is Bearer, then one space, then the token.
Authorization: Bearer dde92200b0744defa1d98e3b3cc0027530c6b31627619dd318c9e3cd88ecd33aThe token is 64 hexadecimal characters with no dashes - which is a quick way to tell it apart from the 36-character dashed login code if you ever confuse the two.
When it goes wrong
Invalid Input : INVALID_VERIFIER
By far the most common failure, and it has several causes. In order of likelihood: the checksum was computed over the wrong string; the code has already been used; you put your user ID where the app key belongs; the digest was uppercased.
Check your implementation against the documented worked example -
IN001_U + demo-secret-0000 + 7a1c0e52-90b4-4f3d-a6e8-5d2c4b1f0a93 hashes the string
IN001_Udemo-secret-00007a1c0e52-90b4-4f3d-a6e8-5d2c4b1f0a93. Then log in again for a fresh code.
Full entry
A 403 on every call after login
The token is probably fine; the IP address is probably not. Infinn checks
both, and rejects an unregistered address with the same empty 401
it uses for a bad token.
Compare curl -s https://api.ipify.org against the Primary IP
Address on your profile. Full entry
Session Expired : Invalid Session Key
The token was valid and no longer is - it expired, you called
Logout, or a login elsewhere superseded it. Re-run the flow.
Token lifetime
My checksum differs from a colleague's for the same inputs
Almost always a trailing newline. In shell, echo appends one
and printf '%s' does not. In any language, make sure you are
hashing the three values concatenated and nothing else.
OAuth is the only login
INFINN API login works only through the OAuth flow on this page: login page, one-time code, GenAcsTok, then Authorization: Bearer <token> on every call. No other login method exists for the API.
The GenAcsTok response may still include a field called susertoken. It is not used for login or for authorising requests. Always use access_token.