简体   繁体   中英

How can I get Google OAuth on a catalyst app?

I've been trying to use Google's OAuth for authentication on a Catalyst app. I've tried using CatalystX::OAuth2 and Catalyst::Authentication::Credential::OAuth but it seems I get stuck on configuration.

I'd like to get it working on Google and then proceed to Facebook

Any good advice out there? I've googled to death, but there doesn't seem to be a lot out there.

I realise this question is almost 2 years old but just in case it helps anyone else, here is some information obtained from a couple of weeks of testing and debugging. I've also published a test oauth2 client project using CatalystX::OAuth2 at https://github.com/simonamor/oauth2-client - it sort of works with Google although I've not done anything with the token yet such as fetching user profile information and the 'protected' page is broken currently. It might be enough to point you in the right direction though.

There seemed to be a problem with CatalystX::OAuth2 in that it didn't send a scope value, nor could I find a way to make it send one and yet Google's API requires one. Not all providers have this requirement so work ok. Having made a slight alteration to a local copy of CatalystX::OAuth2, I managed to get it to authenticate via Google. The (minor) changes are in a fork of this module, also in my github account.

Visit the Google developers console and create the OAuth2 credentials to use. You'll need them below.

To my oauth2client.yml (from the github project referenced above) I added the following:

Plugin::Authentication:
    default:
        credential:
            grant_uri: [provided by google, ends]/o/oauth2/v2/auth
            token_uri: [provided by google, ends]/oauth2/v4/token
            client_id: [issued by google]
            client_secret: [issued by google]
            scope: [provided by google, ends]/auth/userinfo.profile

I don't have a reputation high enough to post more than two links so apologies for missing out parts of the urls above! This was the only real configuration I needed to setup. By modifying the credential settings I've also used it successfully with dropbox.com as well.

I'm still working on the OAuth2 server side of things and those are the default config within the project which is why you need to add an extra section for Google.

if you provided some info, like where you are stuck and why, I might be able to help.

The cpan has an example config. If you are not using a config file, you can also add it in your Catalyst app, though I would recommend using a config file, there just paste in the example with the data you need specifically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM