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.

The idea in four lines
  1. You send the user to an Infinn login page.
  2. They sign in; Infinn sends them back to you with a one-time code.
  3. You swap that code - plus a fingerprint proving you know your secret key - for an access token.
  4. 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

YouBrowserInfinn loginInfinn APIOpen the login URL with your app keyGET /OAuthlogin/…/login?api_key=…&route_to=…User signs in, redirect carries ?code=...You read the one-time codePOST /GenAcsTok { code, checksum }access_token (64 hex characters)checksum = SHA-256(app_key + secret_key + code)Then: Authorization: Bearer <access_token> on every subsequent call
Figure 1. The full exchange. Only the last two arrows involve your code; the first four happen in a browser.

Step 1 - Send the user to the login page

Open this URL in a browser.

Login URL
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=f63c3a3a696392e444acc5b708e13b74a5eaf04d580758d3e11eebf8c748c43a
How to build route_to

route_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.

PartValueNotes
Host and pathhttps://api.infinn.in/OAuthlogin/investor-entry-level/loginThe 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.
You can do this by hand while developing

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.

Step 2
http://localhost/?code=7a1c0e52-90b4-4f3d-a6e8-5d2c4b1f0a93This is your one-time code. Copy it.36 characters with dashes. Valid for one use only.The page itself will not load — that is expected. Only the URL matters.
After logging in, the browser lands on a localhost URL with the code in its query string. Copy the value after ?code=. The page not loading is normal.
Three things about the code
  • 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:

You do not have to write code for this

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.

The string to hash
app_key + secret_key + code
No separators, no spaces, no newline

The 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.

Python
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

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.

Request
HTTP
POST /NorenWClientAPI/GenAcsTok HTTP/1.1
Host: api.infinn.in
Content-Type: text/plain

jData={"code":"7a1c0e52-90b4-4f3d-a6e8-5d2c4b1f0a93","checksum":"c5f9e053..."}
Response
200 OK
{
"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.

Not required for your first token

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.

Python
"""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"))

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.

On all 65 other endpoints
Authorization: Bearer dde92200b0744defa1d98e3b3cc0027530c6b31627619dd318c9e3cd88ecd33a

The 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

One way in

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.

Next

Esc
↑↓ navigate↵ openEsc close/ to search