Client Side
When setting up OAuth2 from client side, you have two options:- Build the entire flow yourself
- Make a request for building the authorization URL
 - Handling the Webview with the created URL
 - Getting the 
codeafter authenticating with ZEBEDE - Making another request for getting the token
 
 - Make use of some of the available OAuth libraries available for the language you are working on, which would handle the initial steps of the flow
- Install and set up configs accordingly to the library
- If PKCE is available on the library you might receive the 
code_verifierfrom the response, after authenticating. - If PKCE is not available, you might need to build the code_challenge and code_verifier yourself.
 
 - If PKCE is available on the library you might receive the 
 - Getting 
codeas response - Making the request for getting the token
 
 - Install and set up configs accordingly to the library
 
Server Side
Node.js
This flow go over all the steps for Logging in with ZBD, from Building the authorization URL, with proper PKCE Keys, to getting the accessToken and calling ZBD API. If you are using a library that provides PKCE guidelines, it will most likely be able to handle the initial flow (building auth URL and getting the code) just fine. In this case, feel free to jump to the Token Section.Building Authorization URL
In case you are setting up the PKCE flow yourself (no usage of libraries), we will need to setup thecode_challenge from a code_verifier which will be used later on, on token request.
getZBDLoginUrlfunction- In this function, we initially Generate PKCE keys: 
verifierandcode_challenge - Then, 
findOneAndUpdaterepresents an generic ORM call for updating the User model, on the database. This way we can, afterwards, retrieve that value for getting the token. - We then Build the URL suffix
 - Url prefix and generated from 
createZBDOauth, which usesoauthlibrary to do so 
- In this function, we initially Generate PKCE keys: 
 generatePKCE- This is where we setup PKCE Keys.
- initially we set the code verifier:
const verifier = base64URLEncode(crypto.randomBytes(32));
 - From the code verifier, the code_challenge is created:
const challenge = base64URLEncode(sha256(verifier));
 
 - initially we set the code verifier:
 
- This is where we setup PKCE Keys.
 
state and code which should be user now for getting the token, and user data:
Getting the token and accessing ZBD API
code and state as query params.
Those values are send as payload on this next request:
- 
First of all, remember we registered the verifier on the User (generic ORM update)? now we retrieve that value:
const user = await User.findOne({ userId: state });
 - 
With the proper verifier, we can now make a post request to the token endpoint, and we should have the token returned.
const res = await getAccessToken({…body})
 - 
Now, by adding the accessToken to request headers, we can fetch data from ZBD API
const response = await getUserData(access_token);