librelist archives

« back to archive

[Flask-OAuth] Multiple Twitter app?

[Flask-OAuth] Multiple Twitter app?

From:
Nguyễn Hồng Quân
Date:
2013-02-19 @ 07:19
Hello, I'm using Flask-OAuth. I want to use different Twitter remote apps
(different consumer_key/consumer_secret) in the same my Flask app. Depend
on the URL of the first access to my web (login?app=xxx, for example), one
of Twitter apps will be used until user choose another.

My problem is that the decorators (@twitter.authorized_handler) are bound
with a specific Twitter app. I don't know how to makes the decorated
functions usable with various Twitter app.

I tried creating a global twitter app will null key:

twitter = oauth.remote_app('twitter',
    base_url='https://api.twitter.com/1/',
    request_token_url='https://api.twitter.com/oauth/request_token',
    access_token_url='https://api.twitter.com/oauth/access_token',
    authorize_url='https://api.twitter.com/oauth/authenticate',
    consumer_key=',
    consumer_secret='')

and update keys later in "login" view but it doesn't work (got an exception
error).

Any help?

-- 
***********************************************
* Nguyễn Hồng Quân                            *
* Y!M: ng_hquan_vn                            *
* Identi.ca: hongquan                         *
***********************************************

Re: [flask] [Flask-OAuth] Multiple Twitter app?

From:
Josh Purvis
Date:
2013-02-20 @ 07:19
I'm not familiar with Flask-OAuth, but there's a fork that I use,
Flask-Rauth, which depends on rauth rather than the python-oauth2 module.
With Flask-Rauth there are two ways to set the consumer/secret keys:

http://flask-rauth.readthedocs.org/en/latest/#set-the-consumer-key-and-secret

Using the first method should allow you to easily accomplish this, by
updating the configuration settings as needed.

Josh

On Tue, Feb 19, 2013 at 2:19 AM, Nguyễn Hồng Quân <ng.hong.quan@gmail.com>wrote:

>
> Hello, I'm using Flask-OAuth. I want to use different Twitter remote apps
> (different consumer_key/consumer_secret) in the same my Flask app. Depend
> on the URL of the first access to my web (login?app=xxx, for example), one
> of Twitter apps will be used until user choose another.
>
> My problem is that the decorators (@twitter.authorized_handler) are bound
> with a specific Twitter app. I don't know how to makes the decorated
> functions usable with various Twitter app.
>
> I tried creating a global twitter app will null key:
>
> twitter = oauth.remote_app('twitter',
>     base_url='https://api.twitter.com/1/',
>     request_token_url='https://api.twitter.com/oauth/request_token',
>     access_token_url='https://api.twitter.com/oauth/access_token',
>     authorize_url='https://api.twitter.com/oauth/authenticate',
>     consumer_key=',
>     consumer_secret='')
>
> and update keys later in "login" view but it doesn't work (got an
> exception error).
>
> Any help?
>
> --
> ***********************************************
> * Nguyễn Hồng Quân                            *
> * Y!M: ng_hquan_vn                            *
> * Identi.ca: hongquan                         *
> ***********************************************

Re: [flask] [Flask-OAuth] Multiple Twitter app?

From:
Nguyễn Hồng Quân
Date:
2013-02-22 @ 01:22
Thank you very much!!!

2013/2/20 Josh Purvis <joshua.purvis@gmail.com>

> I'm not familiar with Flask-OAuth, but there's a fork that I use,
> Flask-Rauth, which depends on rauth rather than the python-oauth2 module.
> With Flask-Rauth there are two ways to set the consumer/secret keys:
>
>
> http://flask-rauth.readthedocs.org/en/latest/#set-the-consumer-key-and-secret
>
> Using the first method should allow you to easily accomplish this, by
> updating the configuration settings as needed.
>



-- 
***********************************************
* Nguyễn Hồng Quân                            *
* Y!M: ng_hquan_vn                            *
* Identi.ca: hongquan                         *
***********************************************

Re: [flask] [Flask-OAuth] Multiple Twitter app?

From:
Anthony Ford
Date:
2013-02-22 @ 17:45
Out of curiosity, is there a reason you don't just spawn multiple oauth
apps?

I.e:

twitter1 = oauth. remote_app('twitter',...
    consumer_key='key1',
    consumer_secret='s3cr3t1')

twitter2 = oauth. remote_app('twitter',...
    consumer_key='key2',
    consumer_secret='s3cr3t2')

And just use the one needed for that route.

Re: [flask] [Flask-OAuth] Multiple Twitter app?

From:
Max Countryman
Date:
2013-02-22 @ 22:46
You could forgo the use of an extension at all and just use rauth directly:

from rauth.service import OAuth1Service

twitter = OAuth2Service(name='twitter',
					    consumer_key='foo',
                                            consumer_secret='bar',
					    ...)

Check out a full example here: 
https://github.com/litl/rauth/blob/master/examples/twitter-timeline-cli.py

Re: [flask] [Flask-OAuth] Multiple Twitter app?

From:
Nguyễn Hồng Quân
Date:
2013-02-23 @ 15:36
Thank Max,

I will give it a try.

2013/2/23 Max Countryman <maxc@me.com>

> You could forgo the use of an extension at all and just use rauth directly:
>
> from rauth.service import OAuth1Service
>
> twitter = OAuth2Service(name='twitter',
>                                             consumer_key='foo',
>                                             consumer_secret='bar',
>                                             ...)
>
> Check out a full example here:
> https://github.com/litl/rauth/blob/master/examples/twitter-timeline-cli.py
>



-- 
***********************************************
* Nguyễn Hồng Quân                            *
* Y!M: ng_hquan_vn                            *
* Identi.ca: hongquan                         *
***********************************************

Re: [flask] [Flask-OAuth] Multiple Twitter app?

From:
Nguyễn Hồng Quân
Date:
2013-02-23 @ 01:37
Because the twitter app is selected by client, based on query string in
URL, my case is login() route.
What make me confused is that until the client access to login(), we don't
know which twiiter app is used but we have to make decorator
@twitter.authorized_handler.
I don't want to make decorator with all twitter app, because the number of
twitter apps is variable (can be add/remove in a config file).

2013/2/23 Anthony Ford <ford.anthonyj@gmail.com>

> Out of curiosity, is there a reason you don't just spawn multiple oauth
> apps?
>
> I.e:
>
> twitter1 = oauth. remote_app('twitter',...
>     consumer_key='key1',
>     consumer_secret='s3cr3t1')
>
> twitter2 = oauth. remote_app('twitter',...
>     consumer_key='key2',
>     consumer_secret='s3cr3t2')
>
> And just use the one needed for that route.
>



-- 
***********************************************
* Nguyễn Hồng Quân                            *
* Y!M: ng_hquan_vn                            *
* Identi.ca: hongquan                         *
***********************************************

Re: [flask] [Flask-OAuth] Multiple Twitter app?

From:
Nguyễn Hồng Quân
Date:
2013-02-23 @ 15:35
Hi Josh,

I checked Flask-Rauth. Look like it is like Flask-Oauth for my case. It
still require to make a fix decorator by a predefined Twitter app, not a
dynamically selected app.

2013/2/20 Josh Purvis <joshua.purvis@gmail.com>

> I'm not familiar with Flask-OAuth, but there's a fork that I use,
> Flask-Rauth, which depends on rauth rather than the python-oauth2 module.
> With Flask-Rauth there are two ways to set the consumer/secret keys:
>
>
> http://flask-rauth.readthedocs.org/en/latest/#set-the-consumer-key-and-secret
>
> Using the first method should allow you to easily accomplish this, by
> updating the configuration settings as needed.
>
> Josh
>


-- 
***********************************************
* Nguyễn Hồng Quân                            *
* Y!M: ng_hquan_vn                            *
* Identi.ca: hongquan                         *
***********************************************