summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Klausner <domm@plix.at>2022-03-10 16:40:56 +0100
committerGitHub <noreply@github.com>2022-03-10 16:40:56 +0100
commit7a30ad354b6432f0cec045882f0ffad286205041 (patch)
treefb5b5b4eb005fdc49930c4850a45e0bb505bd06e
parentff7f4d4efb1f41178d4e07f7bcdf375503fb0f5f (diff)
parent15295a42caa9daf31bf74470bddafd5fb8524dc1 (diff)
Merge pull request #14 from foleybri/withings
Add Withings Service Provider
-rw-r--r--README.md7
-rw-r--r--lib/LWP/Authen/OAuth2.pm6
-rw-r--r--lib/LWP/Authen/OAuth2/ServiceProvider.pm2
-rw-r--r--lib/LWP/Authen/OAuth2/ServiceProvider/Withings.pm117
-rw-r--r--t/LWP/Authen/OAuth2/ServiceProvider/Withings.t23
5 files changed, 155 insertions, 0 deletions
diff --git a/README.md b/README.md
index dd13cf9..055b064 100644
--- a/README.md
+++ b/README.md
@@ -51,6 +51,12 @@ Currently [LWP::Authen::OAuth2](https://metacpan.org/pod/LWP%3A%3AAuthen%3A%3AOA
implemented by [Leon Wright](https://github.com/techman83)
+- Withings
+
+ [LWP::Authen::OAuth2::ServiceProvider::Withings](https://metacpan.org/pod/LWP%3A%3AAuthen%3A%3AOAuth2%3A%3AServiceProvider%3A%3AWithings)
+
+ implemented by [Brian Foley](https://github.com/foleybri)
+
- Yahoo
[LWP::Authen::OAuth2::ServiceProvider::Yahoo](https://metacpan.org/pod/LWP%3A%3AAuthen%3A%3AOAuth2%3A%3AServiceProvider%3A%3AYahoo)
@@ -455,6 +461,7 @@ specified
- [Adam Millerchip](https://github.com/amillerchip) for adding a [Line ](https://metacpan.org/pod/%20https%3A#line.me) Service Provider and some refactoring
- [Michael Stevens](https://github.com/mstevens) for adding a `Yahoo | https://developer.yahoo.com` Service Provider and some dist cleanup
- Nick Morrott for fixing some documentation typos
+- [Brian Foley](https://github.com/foleybri) for adding a https://developer.withings.com Service Provider
# AUTHORS
diff --git a/lib/LWP/Authen/OAuth2.pm b/lib/LWP/Authen/OAuth2.pm
index bbc4c41..f556362 100644
--- a/lib/LWP/Authen/OAuth2.pm
+++ b/lib/LWP/Authen/OAuth2.pm
@@ -378,6 +378,12 @@ L<LWP::Authen::OAuth2::ServiceProvider::Strava>
implemented by L<Leon Wright|https://github.com/techman83>
+=item * Withings
+
+L<LWP::Authen::OAuth2::ServiceProvider::Withings>
+
+implemented by L<Brian Foley|https://github.com/foleybri>
+
=item * Yahoo
L<LWP::Authen::OAuth2::ServiceProvider::Yahoo>
diff --git a/lib/LWP/Authen/OAuth2/ServiceProvider.pm b/lib/LWP/Authen/OAuth2/ServiceProvider.pm
index 048510f..5fa2c79 100644
--- a/lib/LWP/Authen/OAuth2/ServiceProvider.pm
+++ b/lib/LWP/Authen/OAuth2/ServiceProvider.pm
@@ -463,6 +463,8 @@ hopefully useful configuration and documentation:
=item L<LWP::Authen::OAuth2::ServiceProvider::Strava|Strava>
+=item L<LWP::Authen::OAuth2::ServiceProvider::Withings|Withings>
+
=item L<LWP::Authen::OAuth2::ServiceProvider::Yahoo|Yahoo>
=back
diff --git a/lib/LWP/Authen/OAuth2/ServiceProvider/Withings.pm b/lib/LWP/Authen/OAuth2/ServiceProvider/Withings.pm
new file mode 100644
index 0000000..73b6294
--- /dev/null
+++ b/lib/LWP/Authen/OAuth2/ServiceProvider/Withings.pm
@@ -0,0 +1,117 @@
+package LWP::Authen::OAuth2::ServiceProvider::Withings;
+
+# ABSTRACT: Withings OAuth2
+our $VERSION = '0.18'; # VERSION
+
+use strict;
+use warnings;
+use JSON;
+
+our @ISA = qw(LWP::Authen::OAuth2::ServiceProvider);
+
+sub authorization_endpoint {
+ return ' https://account.withings.com/oauth2_user/authorize2';
+}
+
+sub token_endpoint {
+ return 'https://wbsapi.withings.net/v2/oauth2';
+}
+
+sub authorization_required_params {
+ return ( 'client_id', 'state', 'scope', 'redirect_uri', 'response_type' );
+}
+
+sub authorization_default_params {
+ return ( response_type => 'code', state => 'auth', scope => 'user.metrics' );
+}
+
+sub request_required_params {
+ return ( 'action', 'grant_type', 'client_id', 'client_secret', 'code', 'redirect_uri' );
+}
+
+sub request_default_params {
+ return ( grant_type => 'authorization_code', action => 'requesttoken' );
+}
+
+sub refresh_required_params {
+ return ( 'action', 'grant_type', 'client_id', 'client_secret', 'refresh_token' );
+}
+
+sub refresh_default_params {
+ return ( grant_type => 'refresh_token', action => 'requesttoken' );
+}
+
+sub construct_tokens {
+ my ( $self, $oauth2, $response ) = @_;
+
+ my $content = eval { decode_json( $response->content ) };
+ $content = $content->{ 'body' };
+ $response->content( encode_json( $content ) );
+
+ $self->SUPER::construct_tokens( $oauth2, $response );
+}
+
+1;
+
+__END__
+
+=pod
+
+=encoding UTF-8
+
+=head1 NAME
+
+LWP::Authen::OAuth2::ServiceProvider::Withings - Access Withings using OAuth2
+
+=head1 VERSION
+
+version 0.18
+
+=head1 SYNOPSIS
+
+See L<https://developer.withings.com/> for Withings's own documentation. Withings's
+documentation is very detailed, so that is the best place to find detailed
+and up to date info about.
+
+=head1 NAME
+
+LWP::Authen::OAuth2::ServiceProvider::Withings - Access Withings OAuth2 APIs
+
+=head1 VERSION
+
+Version 0.01
+
+=head1 REGISTERING
+
+Before you can use OAuth 2 with Withings you need to register a developer account at
+L<https://account.withings.com/connectionuser/account_create>
+
+You also need to create an application at L<https://account.withings.com/partner/>
+which will provide you with a C<clientId> and C<client_secret>.
+
+=head1 AUTHOR
+
+Brian Foley, C<< <brianf@sindar.net> >>
+
+=head1 AUTHORS
+
+=over 4
+
+=item *
+
+Ben Tilly, <btilly at gmail.com>
+
+=item *
+
+Thomas Klausner <domm@plix.at>
+
+=back
+
+=head1 COPYRIGHT AND LICENSE
+
+This software is copyright (c) 2013 - 2022 by Ben Tilly, Rent.com, Thomas Klausner.
+
+This is free software; you can redistribute it and/or modify it under
+the same terms as the Perl 5 programming language system itself.
+
+=cut
diff --git a/t/LWP/Authen/OAuth2/ServiceProvider/Withings.t b/t/LWP/Authen/OAuth2/ServiceProvider/Withings.t
new file mode 100644
index 0000000..c06e4ad
--- /dev/null
+++ b/t/LWP/Authen/OAuth2/ServiceProvider/Withings.t
@@ -0,0 +1,23 @@
+#! /usr/bin/env perl
+use 5.006;
+use strict;
+use warnings FATAL => 'all';
+use Test::More;
+
+use FindBin qw($Bin);
+use lib "$Bin/../../../../../lib";
+
+BEGIN {
+ use_ok( 'LWP::Authen::OAuth2::ServiceProvider::Withings' ) || print "Bail out!\n";
+ use LWP::Authen::OAuth2;
+
+ my $oauth2 = LWP::Authen::OAuth2->new(
+ client_id => 'Test',
+ client_secret => 'Test',
+ service_provider => "Withings",
+ redirect_uri => "http://127.0.0.1",
+ );
+ isa_ok($oauth2, 'LWP::Authen::OAuth2');
+}
+
+done_testing();