Navigation

    SmartAPI Forum
    • Register
    • Login
    • Search
    • Categories
    • Popular
    • Groups
    • FAQs
    • API Docs

    Guide to secure your SmartAPI Account with two factor authentication

    General Discussion
    0
    104
    1955
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      smrtsaravanan @admin last edited by

      @admin Hi admin, when I try to validate totp i got below error.
      refreshToken= data['data']['refreshToken']
      TypeError: 'NoneType' object is not subscriptable

      S 1 Reply Last reply Reply Quote 0
      • I
        ivar @admin last edited by

        @admin TOTP required only once. Thanks for keeping it simple.

        1 Reply Last reply Reply Quote 0
        • I
          ivar @aj_Brk last edited by

          @aj_Brk thanks

          1 Reply Last reply Reply Quote 0
          • M
            msg2biswajit @msg2biswajit last edited by

            @msg2biswajit :

            Dear All,

            I able to solve PHP API TOTP Login issue and it's working fine for me. Please find the solution as follows for PHP API :

            1. Download "GoogleAuthenticator.php" file from https://github.com/PHPGangsta/GoogleAuthenticator
            
            2. Include the file in your login generation PHP file to create the TOTP automatically as follows 
            
            	require_once("GoogleAuthenticator.php");
            
            3. Now generate the TOTP Automatically as follows :
            
            	$authenticator = new PHPGangsta_GoogleAuthenticator();
            	$secret = "YOUR SECRET CODE, WHICH SHOWS DURING ENABLE TOTP UNDER GOOGLE BAR CODE";
            	$totp = $authenticator->getCode($secret);
            
            4. Update the PHP API function in "SmartApi.php" file as follows :
            
            	public static function GenerateSession($clientcode, $password, $totp)
            
            5. Update the API Parameter in "SmartApi.php" file as follows :
            
            	$api_parameter = ['clientcode'=>$clientcode,'password'=>$password,'totp'=>$totp];
            

            Enjoy PHP API and login. Thanks.

            1 Reply Last reply Reply Quote 0
            • S
              Sukhwant280 @ravindra.e last edited by

              @ravindra-e Thanks for the code.. Its working for me but it fails when I pass this token to next steps i.e.
              smartApi.getProfile(refreshToken)
              smartApi.generateToken(refreshToken)
              Error is: Invalid json response.

              My understanding is that he refresh token is valid until 5 AM next day, hence I can use the same refresh Token whenever I want to make API calls.

              Please correct me if my understanding is wrong here. Thanks in advance

              @admin , @Ashok - Please help.

              R 1 Reply Last reply Reply Quote 0
              • S
                smrtsaravanan @smrtsaravanan last edited by

                @smrtsaravanan it is working fine now. Ignore it.

                I have made a couple of changes. 1st I have declared it like below

                obj=SmartConnect(api_key=apikey)
                totp = pyotp.TOTP(s='yourkey')
                print("pyotp",totp.now())
                attempts = 5
                while attempts > 0:
                attempts = attempts-1
                data = obj.generateSession(username, pwd, totp.now())
                print(data)
                if data['status']:
                break
                tt.sleep(2)

                and entered my new API key.

                Hope it helps!

                1 Reply Last reply Reply Quote 0
                • W
                  webseos @aj_Brk last edited by webseos

                  @aj_Brk I have used similar code as given below , but got the following exception
                  Exception : Object of type TOTP is not JSON serializable

                  but then I solved the problem

                  But then I added last two lines and problem solved the last two lines given at the end of the following code- qrOtp is the code generated here : https://smartapi.angelbroking.com/enable-totp below the QR Code. So you have to generate your own qrOtp code here in this site. Then Install pyotp using command line "pip install pyotp"

                  My Code Below ( Last line totp = totp.now() is very important)

                  from smartapi import SmartConnect #or from smartapi.smartConnect import SmartConnect
                  import config
                  import pyotp

                  client_code = "aaaaaa"
                  client_pass = "bbbbbb"

                  apiKey="yyyyyyy"
                  qrOtp = "xxxxxxxx"
                  totp = pyotp.TOTP(qrOtp)
                  totp = totp.now()

                  smartapiObj =SmartConnect(apiKey)

                  data = smartapiObj.generateSession(client_code,client_pass,totp)
                  print(data)

                  C S 2 Replies Last reply Reply Quote 2
                  • ?
                    A Former User last edited by

                    @admin What about golang library it is updated for totp changes.

                    A 1 Reply Last reply Reply Quote 0
                    • A
                      admin @Guest last edited by admin

                      Hi @patisupa , we have modified the goLang. Please refer here - https://github.com/angel-one/smartapigo

                      ? 1 Reply Last reply Reply Quote 0
                      • ?
                        A Former User @admin last edited by

                        @admin thanks for update

                        1 Reply Last reply Reply Quote 0
                        • R
                          ravindra.e @smrtsaravanan last edited by

                          @smrtsaravanan Can you please paste your code here?

                          1 Reply Last reply Reply Quote 0
                          • R
                            ravindra.e @Sukhwant280 last edited by

                            @Sukhwant280 said in Guide to secure your SmartAPI Account with two factor authentication:

                            smartApi.generateToken(refreshToken)

                            Why would you need smartApi.generateToken(refreshToken)?

                            1 Reply Last reply Reply Quote 0
                            • P
                              patanjali196 last edited by patanjali196

                              @admin I am unable to login to smartapi.angelbroking.com/enable-totp URL , But I am able to login to https://smartapi.angelbroking.com/apps with my credentials. But to ToTP i am not able to login, Its saying invalid userid or password. Please help me to resolve this issue.
                              Thanks.

                              1 Reply Last reply Reply Quote 0
                              • G
                                ganesh @aj_Brk last edited by

                                @aj_Brk not working for me

                                1 Reply Last reply Reply Quote 0
                                • G
                                  ganesh @gokul last edited by

                                  @gokul i am also getting same error

                                  R 1 Reply Last reply Reply Quote 0
                                  • R
                                    ravindra.e @ganesh last edited by

                                    @ganesh
                                    update using pip install smartapi-python --upgrade

                                    1 Reply Last reply Reply Quote 0
                                    • Mr Depp
                                      Mr Depp last edited by

                                      Hello team.

                                      What about the c#.net sdk update ? did you updated to the library or setting some another way to use it ?

                                      N 1 Reply Last reply Reply Quote 0
                                      • N
                                        Nichil72 @Mr Depp last edited by

                                        @Mr-Depp said in Guide to secure your SmartAPI Account with two factor authentication:

                                        Hello team.

                                        What about the c#.net sdk update ? did you updated to the library or setting some another way to use it ?

                                        Hello Team,
                                        Please update on C#.Net sdk ASAP.

                                        1 Reply Last reply Reply Quote 0
                                        • C
                                          cthomas @webseos last edited by

                                          @webseos Thanks for your simple and effective answer. This works really well.

                                          1 Reply Last reply Reply Quote 0
                                          • N
                                            nikaashpuri last edited by

                                            I have suddenly started getting the following error when logging in using username, password, and otp using the API:

                                            File "abc.py", line 327, in test_login_access
                                                data = angel_obj.generateSession(user_id, password, totp.now())
                                              File "/home/ubuntu/py37-venv/lib/python3.7/site-packages/smartapi/smartConnect.py", line 239, in generateSession
                                                id=user['data']['clientcode']
                                            TypeError: 'NoneType' object is not subscriptable
                                            

                                            What is going on here?

                                            S 1 Reply Last reply Reply Quote 0
                                            • First post
                                              Last post