<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Net::OAuth2 &#8211; blog.fukata.org</title>
	<atom:link href="/archives/tag/netoauth2/feed/" rel="self" type="application/rss+xml" />
	<link>/</link>
	<description>旅するプログラマ</description>
	<lastBuildDate>Fri, 11 Aug 2017 22:58:48 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.6</generator>
	<item>
		<title>Net::OAuth2を使ってGoogle OAuth2をやってみた</title>
		<link>/archives/7056/</link>
					<comments>/archives/7056/#respond</comments>
		
		<dc:creator><![CDATA[fukata]]></dc:creator>
		<pubDate>Tue, 10 Apr 2012 02:19:38 +0000</pubDate>
				<category><![CDATA[開発]]></category>
		<category><![CDATA[Dancer]]></category>
		<category><![CDATA[Google OAuth]]></category>
		<category><![CDATA[Net::OAuth2]]></category>
		<guid isPermaLink="false">http://fukata.org/?p=7056</guid>

					<description><![CDATA[perlのOAuthモジュールである「Net::OAuth2」を使い、Google OAuth2を行なってみたのでログとして残しておきたいと思います。 まず、OAuthで使用するアプリはここから作成し ... <a href="/archives/7056/"> 続きを読む</a>]]></description>
										<content:encoded><![CDATA[<p>perlのOAuthモジュールである「<a href="https://search.cpan.org/~kgrennan/Net-OAuth2-0.07/lib/Net/OAuth2.pm">Net::OAuth2</a>」を使い、Google OAuth2を行なってみたのでログとして残しておきたいと思います。</p>
<p>まず、OAuthで使用するアプリは<a href="https://code.google.com/apis/console#access">ここ</a>から作成しておきます。</p>
<p>ソースは下記のようになりました。</p>
<p><span id="more-7056"></span></p>
<div class="ad_section"><div class="ad_title">広告</div><div class="ad_body"><script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<!-- blog-content-bottom1 -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-9703571485671477"
     data-ad-slot="4353022998"
     data-ad-format="auto"></ins>
<script>
(adsbygoogle = window.adsbygoogle || []).push({});
</script></div></div>
<p>FWはDancerを使っているため、一部Dancerのシンタックスが含まれています。</p>
<pre lang="perl">
use Dancer ':syntax';
use Net::OAuth2::Client;
  
sub oauth {
    return Net::OAuth2::Client->new(
        "Client ID",
        "Client secret",
        site             => 'https://www.googleapis.com/',
        authorize_url    => 'https://accounts.google.com/o/oauth2/auth',
        access_token_url => 'https://accounts.google.com/o/oauth2/token',
    )->web_server( redirect_uri => uri_for('/auth/google/callback') );
}

get '/auth/google' => sub {
    my $url  = oauth->authorize_url(
        scope => 'https://www.googleapis.com/auth/userinfo.profile',
    );
    redirect $url;
};

get '/auth/google/callback' => sub {
    if ( params->{error} ) {
        # OAuth拒否
    }
    elsif ( params->{code} ) {
        # OAuth許可
        my $access_token = oauth->get_access_token( params->{code} );
        my $response = $access_token->get('/oauth2/v1/userinfo');
        if ( $response->is_success ) {
            my $user = from_json( $response->decoded_content, { utf8 => 1 } );
            # ユーザ情報を使って何か処理...
        }
    }
};
</pre>
]]></content:encoded>
					
					<wfw:commentRss>/archives/7056/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
