How to use Mobile-ID in Python
Mobile-ID (Mobiil-ID) is a personal mobile identity in Estonia and Lithuania, provided by an additional application on a SIM card.
The good thing is that it is backed by government and provides the same level of security for authentication and digital signatures as a national ID card without the need of having a smart card reader.
So, while thinking on adding Mobile-ID authentication to our era.ee free domain service, I have came up with this Python code, which is incredibly simple. Replace +372xxxxxx with your own phone number for testing and register it at https://demo.sk.ee/MIDCertsReg/ before running the code.
from sys import exit
from suds.client import Client
import time
import logging
logging.basicConfig(level=logging.INFO)
url = 'https://tsp.demo.sk.ee/?wsdl' # test env
client = Client(url)
mid = client.service.MobileAuthenticate('', '', '+372xxxxxx', 'EST', 'Testimine', 'era.ee login', '12345678901234567890', 'asynchClientServer', 0, False, False)
if mid.Status != 'OK':
print mid.Status
exit(1)
print 'Challenge: ' + mid.ChallengeID
status = 'OUTSTANDING_TRANSACTION'
while status == 'OUTSTANDING_TRANSACTION':
time.sleep(2)
status = client.service.GetMobileAuthenticateStatus(mid.Sesscode, False).Status
if status != 'USER_AUTHENTICATED':
print status
exit(2)
print 'Authenticated: ' + mid.UserGivenname + ' ' + mid.UserSurname + ', ' + mid.UserIDCode
Don’t forget to install the SUDS Python library that does the magic of creating SOAP requests (apt-get install python-suds on Debian & Ubuntu)
Archived comments
ornyx 2012-03-07T20:17:07.200Z
In real environment sadly this script does not work for me also customer has agreement with sk.ee - returns 101 server fault. What is the real URL and request? Is everything the same?
Our recent stories
A bank built in 8 months - licence confirmed, deadline met
Build or buy? When the client came to us, that question was still open. We recommended building. No vendor lock-in, no paying for features you'll never use, no waiting on someone else's roadmap. A codebase you own. A product you control. They agreed. That put more weight on us - and we were fine with that.
The story of Mihkel and Misha creating the Fussball app
We now have our own internal app called Fussball. We talked to its creators, Misha and Mihkel, about what it does and what motivated them to spend their free time building it.
The Codeborne Christmas beer brewing diaries
It was a sunny day in September. Quite warm for that time of year. We were sitting with my colleague Tiit on the roof terrace in the Codeborne office as we do every now and then. I ask him for advice on occasion - after all, what are the more experienced colleagues good for otherwise?