Integrate Binance Login with your App
#
Binance Open SDKBinance Open SDK (hereinafter called SDK) provides two authorization ways, through Binance ap or web page, which is convenient to authorize the Binance account safely and quickly. SDK will adopt different ways according to the situations and users' choices.
To begin, your app should identify the needed permissions (scope) firstly. Setup and register your app with Binance Accounts, and get your client_id . For now, Binance Login(Oauth2.0), is only provided to close ecosystem partners now. Please reach to our business team for more details.
#
Process IntroductionThe Binance app will be called to authorize when the user clicks to login with the Binance account in the app. If the user does not install the Binance app supported the authorization,there would be a prompt for the user to authorize through the browser or download the Binance app. The result would be returned to the app after the authorization is finished.
#
Integrate SDK for Android#
How to use?#
Create a urlFirst you need a url start with 'https://accounts.binance.com/oauth/authorize' to construct an intent.
Add the query parameters listed on the
parameter and description
table(At the article's end).Eexample:
https://accounts.binance.com/oauth/authorize?response_type=code&scope=user:email,user:rsa,user:kyc,user:status,user:mobile,bind:subAccount&client_id=xxxxxxxxx&redirect_uri=https%3A%2F%2Faccounts.pexpay.com%2Fen%2Foauth-handle&state=76ea8434ceca47ada566308030ef5f5c&bundleID=com.xxx.www
#
Create an Intent and start oauth activity- Using the URL you created, to create an new Intent, then start the Activity:
Or
redirect_uri
#
Once user finish the oauth successfully, we will call the url you provided through For example, if you pass "app://yourapp.com" as
redirect_uri
Once user finish oauth.
- If success:
We will callapp://yourapp.com?code=xxxxx&state=xxxxx
as intent uri with action:Intent.ACTION_VIEW
and category:Intent.CATEGORY_BROWSABLE
.
After getting the code, it will be sent to your server. Your server will then send it to the oauth server to get the user data and complete the authorization process. - If failed:
We will call
app://yourapp.com?error=xxxxx&error_description=xxxxx
as intent uri with action:Intent.ACTION_VIEW
and category:Intent.CATEGORY_BROWSABLE
.
You can find the error and error_description on theerror and error_description
table(At the article's end).
- If success:
So if you want to get the result of this OAuth action, you should announce that your app can consume the intent, you can achieve this by adding those codes into your AndroidMainfest.xml:
Then finally get the uri on
onCreate
oronNewIntent
:
Android App Links. So sometimes when the user's application's AppUrls haven't finished verified, this function may not work correctly. Which means you will always be led to the website to do the OAuth.#
Please note that, this function is based on#
Integrate SDK for iOS#
How to use?#
Create a urlFirst you need a url 'https://accounts.binance.com/oauth/authorize'
Add the query parameters listed on the parameter and description table(At the article's end).
Eexample Scheme:
https://accounts.binance.com/oauth/authorize?response_type=code&scope=user:email,user:rsa,user:kyc,user:status,user:mobile,bind:subAccount&client_id=xxxxxxxxx&redirect_uri=oauthdemo%3A%2F%2Flogin&state=76ea8434ceca47ada566308030ef5f5c&bundleID=com.xxx.www
Eexample Universal link:
https://accounts.binance.com/oauth/authorize?response_type=code&scope=user:email,user:rsa,user:kyc,user:status,user:mobile,bind:subAccount&client_id=xxxxxxxxx&redirect_uri=https%3A%2F%2Faccounts.pexpay.com%2Fen%2Foauth-handle&state=76ea8434ceca47ada566308030ef5f5c&bundleID=com.xxx.www"
If you use scheme, you must add path, otherwise it will definitely fail.
redirect_uri=oauthdemo%3A%2F%2Flogin
#
Start oauthUsing the url you created to open binance app
#
Get oauth resultOnce user finish the oauth successfully, we will call the url you provided through
redirect_uri
and get your result
After getting the code, it will be sent to your server. Your server will then send it to the oauth server to get the user data and complete the authorization process.
#
Error TypeEexample
You can find the error and error_description on the
error and error_description
table(At the article's end).
#
Add On Tables#
error and error_description:error description cancelled User has cancelled the authorization manually. readClientInfoFailed Binance App read your app's information failed. invaildClientInfo You app's information is invalid.
#
parameter and description:parameter description redirectUri The URL in your application where users will be redirected after web authorization. scope List of scopes enum your application requests access to, with comma ( ,
) seperated.state The CSRF token to protect against CSRF (cross-site request forgery) attacks. response_type Always use code
client_id Binance client ID bundleID (Optional) Bundle ID of your app