Base64 Examples

The Client Application must send the clientId and the clientSecret separated by a : encoded in Base 64. The format will be like: Base64(clientId:clientSecret)

Many variants of Base64 exist. The variant that must be used is RFC 4648. Line wrapping should be disabled.


In Java, the Base64 class uses RFC 4648 by default.

java.util.Base64.Encoder encoder = java.util.Base64.getEncoder();
String clientIdAndSecret = clientId + ":" + clientSecret;
encodedClientIdAndSecret = encoder.encodeToString(clientIdAndSecret.getBytes("UTF-8"));


In Ruby, the function strict_encode64 uses RFC 4648.

require 'base64'
token = Base64.strict_encode64(id + ':' + secret)

Shell with GNU Base64

In a shell that has the GNU version of base64, base64 can be used to encode the clientId and clientSecret.

Most Linux shells will have the GNU version of base64. Git Bash can be used on Windows. However, the default Mac OS X version of base64 is not the GNU version and lacks the option to disable line wrapping.

# echo requires the -n option to avoid encoding an additional \n
# base64 requires the -w option is for compatibility with RFC 4648 (disable line wrapping)
echo -n "clientId:clientSecret" | base64 -w 0