Package: masonite-socialite
Masonite SocialiteFlexible Social Authentication for Masonite FrameworkRead our Blog|Follow us on TwitterTable of ContentsExampleInstallationConfigurationRoutingControllersProvidersSupportExampleclassSocialAuthController(Controller):"""SocialAuthController Controller Class."""deflogin(self,socialite:Socialite):returnsocialite.driver('github').redirect()defcallback(self,view:View,request:Request,socialite:Socialite):user=socialite.driver('github').user()# Your application logic here.Installation# Using pip$pipinstallmasonite-socialite# Using Pipenv$pipenvinstallmasonite-socialite# Using Poetry$poetryaddmasonite-socialiteAddSocialiteProviderto your providers list inconfig/providers.py:fromsocialite.providersimportSocialiteProviderPROVIDERS=[# Third Party ProvidersSocialiteProvider,]This will add a newsocialite:installcommand to craft. Then run in your terminal:craftsocialite:installConfigurationBefore using Socialite, you need to get credentials from the provider(s) you want to use. Depending on the providers your application requires, you'll put the right credentials in the.envfile:# FacebookSOCIAL_AUTH_FACEBOOK_KEY=''SOCIAL_AUTH_FACEBOOK_SECRET=''SOCIAL_AUTH_FACEBOOK_REDIRECT_URI=''# TwitterSOCIAL_AUTH_TWITTER_KEY=''SOCIAL_AUTH_TWITTER_SECRET=''SOCIAL_AUTH_TWITTER_REDIRECT_URI=''# GoogleSOCIAL_AUTH_GOOGLE_OAUTH2_KEY=''SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET=''SOCIAL_AUTH_GOOGLE_OAUTH2_REDIRECT_URI=''# GithubSOCIAL_AUTH_GITHUB_KEY=''SOCIAL_AUTH_GITHUB_SECRET=''SOCIAL_AUTH_GITHUB_REDIRECT_URI=''# LinkedInSOCIAL_AUTH_LINKEDIN_KEY=''SOCIAL_AUTH_LINKEDIN_SECRET=''SOCIAL_AUTH_LINKEDIN_OAUTH2_REDIRECT_URI=''If you don't know how to get those values, you can find a detailed guidehere.RoutingYou need two routes: one for redirecting the user to the appropriate OAuth provider, and another for receiving the callback from the provider after authentication."""Web Routes."""frommasonite.routesimportGetROUTES=[Get('auth/@provider','SocialAuthController@login'),Get('auth/@provider/callback','SocialAuthController@callback'),]ControllersYou can accessSocialiteusing the Socialite helper:frommasonite.authimportAuthfrommasonite.controllersimportControllerfrommasonite.requestimportRequestfromapp.UserimportUserfromsocialiteimportSocialiteclassSocialAuthController(Controller):"""Controller For Social Authentication."""defredirect_to_provider(self,request:Request,socialite:Socialite):"""Redirect the user to the authentication page"""returnsocialite.driver(request.provider).redirect()defhandle_provider_callback(self,request:Request,socialite:Socialite,auth:Auth):"""Obtain the user information"""user=socialite.driver(request.provider).user()# => print(user)returnrequest.redirect('/home')ProvidersGithubFacebookTwitterGoogleLinkedinGitlabWe are accepting new providers. Send new provider pull requests. You can follow this tutorial to add a new provider.SupportMasonite Socialiteappreciates help from a wide range of different backgrounds. Small improvements or fixes are always appreciated and issues labeled as easy may be a good starting point. If you are considering larger contributions outside the traditional coding work, please contact us throughhellomasonite@gmail.com.