OAuth 2.0
OAuth2 Authentication in MoonSDK
MoonSDK supports OAuth2 authentication with various providers, allowing users to log in using their existing accounts on these platforms. This documentation page explains how to use the MoonSDK class functions for OAuth2 authentication and provides examples of the process of redirection to code exchange for a session token.
Available Providers
MoonSDK supports the following OAuth2 providers:
Discord
GitHub
Google
Twitter
OAuth2 Authentication Process
The OAuth2 authentication process involves the following steps:
Redirect the user to the OAuth2 login page of the provider.
The user logs in to their account on the provider's website.
The provider redirects the user back to your application with a code.
Exchange the code for a session token.
Example: Discord OAuth2 Authentication
Here's an example of how to use the performDiscordOAuth
and performDiscordOauthCodeExchange
functions to authenticate a user with Discord:
Redirect the user to the Discord OAuth2 login page:
The user logs in to their Discord account and is redirected back to your application with a code in the URL query string.
Exchange the code for a session token:
The performDiscordOauthCodeExchange
function sends a request to the Discord API to exchange the code for a session token and returns the token.
Example: GitHub OAuth2 Authentication
Here's an example of how to use the performGithubOAuth
and performGithubOauthCodeExchange
functions to authenticate a user with GitHub:
Redirect the user to the GitHub OAuth2 login page:
The user logs in to their GitHub account and is redirected back to your application with a code in the URL query string.
Exchange the code for a session token:
The performGithubOauthCodeExchange
function sends a request to the GitHub API to exchange the code for a session token and returns the token.
Example: Google OAuth2 Authentication
Here's an example of how to use the performGoogleOAuth
and performGoogleOauthCodeExchange
functions to authenticate a user with Google:
Redirect the user to the Google OAuth2 login page:
The user logs in to their Google account and is redirected back to your application with a code in the URL query string.
Exchange the code for a session token:
The performGoogleOauthCodeExchange
function sends a request to the Google API to exchange the code for a session token and returns the token.
Example: Twitter OAuth2 Authentication
Here's an example of how to use the performTwitterOauth
and performTwitterOauthCodeExchange
functions to authenticate a user with Twitter:
Redirect the user to the Twitter OAuth2 login page:
The user logs in to their Twitter account and is redirected back to your application with a code in the URL query string.
Exchange the code for a session token:
The performTwitterOauthCodeExchange
function sends a request to the Twitter API to exchange the code for a session token and returns the token.
Conclusion
MoonSDK supports OAuth2 authentication with various providers, allowing users to log in using their existing accounts on these platforms. This documentation page explains how to use the MoonSDK class functions for OAuth2 authentication and provides examples of the process of redirection to code exchange for a session token. Whether you're building a new application or looking to improve the authentication flow of an existing one, MoonSDK's OAuth2 support is a great choice.
Last updated