Example #1
0
 def __init__(self, redirect_uri):
     OAuth2Service.__init__(self,
         client_id=app.config['FACEBOOK_CLIENT_ID'],
         client_secret=app.config['FACEBOOK_CLIENT_SECRET'],
         name='facebook',
         authorize_url='https://graph.facebook.com/oauth/authorize',
         access_token_url='https://graph.facebook.com/oauth/access_token',
         base_url='https://graph.facebook.com/')
     self.redirect_uri = redirect_uri
Example #2
0
 def __init__(self, redirect_uri):
     OAuth2Service.__init__(self,
         client_id=web.config.facebook_client_id,
         client_secret=web.config.facebook_client_secret,
         name='facebook',
         authorize_url='https://graph.facebook.com/oauth/authorize',
         access_token_url='https://graph.facebook.com/oauth/access_token',
         base_url='https://graph.facebook.com/')
     self.redirect_uri = redirect_uri
Example #3
0
 def __init__(self, redirect_uri):
     OAuth2Service.__init__(self,
         client_id=app.config['GOOGLE_CLIENT_ID'],
         client_secret=app.config['GOOGLE_CLIENT_SECRET'],
         name='google',
         authorize_url='https://accounts.google.com/o/oauth2/auth',
         access_token_url='https://accounts.google.com/o/oauth2/token',
         base_url='https://www.googleapis.com/oauth2/v1/')
     self.redirect_uri = redirect_uri
Example #4
0
 def __init__(self, redirect_uri):
     OAuth2Service.__init__(self,
         client_id=app.config['MICROSOFT_CLIENT_ID'],
         client_secret=app.config['MICROSOFT_CLIENT_SECRET'],
         name='microsoft',
         authorize_url='https://login.live.com/oauth20_authorize.srf',
         access_token_url='https://login.live.com/oauth20_token.srf',
         base_url='https://apis.live.net/v5.0/')
     self.redirect_uri = redirect_uri
Example #5
0
 def __init__(self, redirect_uri):
     OAuth2Service.__init__(self, 
         client_id=web.config.github_client_id,
         client_secret=web.config.github_client_secret,
         name='github',
         authorize_url='https://github.com/login/oauth/authorize',
         access_token_url='https://github.com/login/oauth/access_token',
         base_url='https://api.github.com/')
     self.redirect_uri = redirect_uri
Example #6
0
 def __init__(self, redirect_uri):
     OAuth2Service.__init__(self,
         client_id=web.config.google_client_id,
         client_secret=web.config.google_client_secret,
         name='google',
         authorize_url='https://accounts.google.com/o/oauth2/auth',
         access_token_url='https://accounts.google.com/o/oauth2/token',
         base_url='https://www.googleapis.com/oauth2/v1/')
     self.redirect_uri = redirect_uri
Example #7
0
    def __init__(self,
                 keyfile,
                 tokenfile=None,
                 base_url="https://fantasysports.yahooapis.com",
                 request_period=0):

        self.key = ClientKey.from_file(keyfile)

        self.tokenfile = tokenfile
        if self.tokenfile and os.path.exists(self.tokenfile):
            self.token = Token.from_file(self.tokenfile)
        else:
            self.token = Token()

        self.oauth = OAuth2Service(
            client_id=self.key.client_id,
            client_secret=self.key.client_secret,
            name="yahoo",
            authorize_url="https://api.login.yahoo.com/oauth2/request_auth",
            access_token_url="https://api.login.yahoo.com/oauth2/get_token",
            base_url=base_url,
        )

        self.session = None

        self._update_token()

        self.session = self.oauth.get_session(self.token.access_token)

        self.last_request = time.time()
        self.request_period = request_period
Example #8
0
    def get_authorize_url(self, callback_url, state=None):
        """
        Returns the Authorize URL as returned by QB, and specified by OAuth 2.0a.
        :return URI:
        """
        auth_service = OAuth2Service(
            name='quickbooks',
            client_id=self.client_id,
            client_secret=self.client_secret,
            authorize_url=self.authorize_url,
            access_token_url=self.access_token_url,
            base_url=self.base_url,
        )

        params = {
            'client_id': self.client_id,
            'response_type': 'code',
            'scope': 'com.intuit.quickbooks.accounting',
            'redirect_uri': callback_url,
            'state': state,
        }

        url = auth_service.get_authorize_url(**params)

        return url
Example #9
0
    def authorized(self, code, redirect_uri):
        """
        facebook login authorize
        :param code: response code authorize
        :param redirect_uri: redirect url
        :return: user data
        """
        facebook = OAuth2Service(
            client_id=self.__app_id,
            client_secret=self.__app_secret,
            name=self.__class__.__name__,
            authorize_url='https://www.facebook.com/dialog/oauth',
            access_token_url='https://graph.facebook.com/oauth/access_token',
            base_url=self.graph_uri_base)
        data = dict(code=code, redirect_uri=redirect_uri)
        fb_session = facebook.get_auth_session(data=data,
                                               decoder=self._oauth_decoder)
        extended_user_access_token = self.extend_user_access_token(
            fb_session.access_token)
        print(f'Facebook access token: {fb_session.access_token}')
        # self.check_valid_access_token(input_access_token=extended_user_access_token)
        user_data = fb_session.get('me').json()
        data = {
            'username': user_data['name'],
            'user_id': user_data['id'],
            'user_access_token': extended_user_access_token
        }
        user = User(**data)
        user.save()

        return data
Example #10
0
    def facebook_login(self):
        """
        login facebook
        :return: redirect login url
        """
        facebook = OAuth2Service(
            client_id=self.__app_id,
            client_secret=self.__app_secret,
            name=self.__class__.__name__,
            authorize_url='https://www.facebook.com/dialog/oauth',
            access_token_url='https://graph.facebook.com/oauth/access_token',
            base_url=self.graph_uri_base)

        # redirect URL https://www.facebook.com/connect/login_success.html
        redirect_uri = f'https://{"ff7e3ac981ca"}.ngrok.io/merchant/facebook/token'
        params = {
            'redirect_uri':
            'https://ff7e3ac981ca.ngrok.io/merchant/facebook/token',
            'scope':
            'catalog_management, ads_management, pages_manage_posts, instagram_basic',
            'auth_type': 'reauthorize'
        }
        authorize_url = facebook.get_authorize_url(**params)

        return authorize_url
Example #11
0
def stripe_connect(request):
    # Set up your OAuth flow parameters
    stripe_connect_service = OAuth2Service(
        name='stripe',
        client_id=settings.CLIENT_TOKEN_STRIPE,
        client_secret=settings.API_TOKEN_STRIPE,
        authorize_url='https://connect.stripe.com/oauth/authorize',
        access_token_url='https://connect.stripe.com/oauth/token',
        base_url='https://api.stripe.com/',
    )

    # They return to your site from filling out a form on stripe and...
    # There's a temporary code returned when they're redirected to your site.
    # In Django, you would grab it like this
    code = request.GET.get('code', '')
    data = {'grant_type': 'authorization_code', 'code': code}

    # Use your OAuth service to get a response
    resp = stripe_connect_service.get_raw_access_token(method='POST',
                                                       data=data)

    # They returned JSON
    stripe_payload = json.loads(resp.text)
    print(stripe_payload)

    # They return four parameters.  We only care about the 'access_token' right now
    connect_access_token = stripe_payload['stripe_user_id']

    request.user.stripe_client_id = connect_access_token
    request.user.save()

    return render(request, 'voluntariat/stripe/stripe.html')
Example #12
0
def get_sign_in_view(target):
    signin_url = request.url_root + target
    oauth_service = OAuth2Service(
        name="google",
        client_id=current_app.config.get("GOOGLE_LOGIN_CLIENT_ID", None),
        client_secret=current_app.config.get("GOOGLE_LOGIN_CLIENT_SECRET",
                                             None),
        authorize_url=google_params.get("authorization_endpoint"),
        base_url=google_params.get("userinfo_endpoint"),
        access_token_url=google_params.get("token_endpoint"))

    if "code" in request.args:
        oauth_session = oauth_service.get_auth_session(data={
            "code":
            request.args["code"],
            "grant_type":
            "authorization_code",
            "redirect_uri":
            signin_url
        },
                                                       decoder=json.loads)

        user_data = oauth_session.get("").json()
        user = load_user(user_data["email"])
        if user:
            if user.is_active():
                print("user is active")
                flask_login.login_user(user)
                redirect_to = session.pop("post_login_page", None)
                try:
                    endpoint, arguments = current_app.url_map.bind(
                        'localhost').match(redirect_to)
                except Exception as e:
                    redirect_to = None
                if redirect_to:
                    return redirect(redirect_to)
                else:
                    return redirect(url_for("user.index"))
            else:
                error_message = "Account not active ({})".format(
                    user_data["email"])
                return render_template("/sign_in.html",
                                       error_message=error_message)
        else:
            error_message = "Not an authorized user ({})".format(
                user_data["email"])
            return render_template("/sign_in.html",
                                   error_message=error_message)
    elif "authorize" in request.args:
        authorize_url = oauth_service.get_authorize_url(
            scope="email",
            response_type="code",
            prompt="select_account",
            redirect_uri=signin_url)
        print(authorize_url)

        return redirect()
    else:
        return render_template("/sign_in.html")
Example #13
0
 def __init__(self):
     self.service = OAuth2Service(
         name='dataporten',
         client_id=secret_settings.OAUTH_CREDENTIALS['id'],
         client_secret=secret_settings.OAUTH_CREDENTIALS['secret'],
         authorize_url='https://auth.dataporten.no/oauth/authorization',
         access_token_url='https://auth.dataporten.no/oauth/token',
         base_url='https://auth.dataporten.no/')
Example #14
0
 def __init__(self, client_id, client_secret, redirect_uri):
     self.outh_service = OAuth2Service(client_id=client_id,
                                       client_secret=client_secret,
                                       name=OAUTH_SERVICE_NAME,
                                       authorize_url=AUTHORIZE_URL,
                                       access_token_url=ACCESS_TOKEN,
                                       base_url=BASE_URL.format(""))
     self.redirect_uri = redirect_uri
Example #15
0
 def oauth_2_service(self):
     service = OAuth2Service(name="yahoo",
                             client_id=self.consumer_key,
                             client_secret=self.consumer_secret,
                             base_url=self.url_base,
                             authorize_url=YahooOAuth2Urls.url_request_auth,
                             access_token_url=YahooOAuth2Urls.url_get_token)
     return service
Example #16
0
 def __init__(self):
     super(XDSignIn, self).__init__('xd')
     self.service = OAuth2Service(name='xd',
                                  client_id=self.consumer_id,
                                  client_secret=self.consumer_secret,
                                  authorize_url='',
                                  access_token_url='',
                                  base_url='')
Example #17
0
 def service(self):
     return OAuth2Service(
         client_id=self.client_id,
         client_secret=self.client_secret,
         name='github',
         authorize_url='https://github.com/login/oauth/authorize',
         access_token_url='https://github.com/login/oauth/access_token',
         base_url='https://api.github.com/')
Example #18
0
def get_oauth_service(service):
	""" Returns the OAuth2Service instance """
	fields = frappe.db.get_values(
		"APP Token",
		service,
		["name", "client_id", "client_secret", "authorize_url", "access_token_url", "base_url"],
	as_dict=True)[0]
	return OAuth2Service(**fields)
Example #19
0
 def __init__(self):
     super(FacebookSignIn, self).__init__('facebook')
     self.service = OAuth2Service(
         client_id=self.consumer_id,
         client_secret=self.consumer_secret,
         authorize_url='https://graph.facebook.com/oauth/authorize',
         access_token_url='https://graph.facebook.com/oauth/access_token',
         base_url='https://graph.facebook.com/')
Example #20
0
	def GetOauthService(self):
		oauth_service = OAuth2Service(
		client_id = self.clientId,
		client_secret = self.clientSecret,
		name="irida",
		access_token_url = self.baseURL + "oauth/token",
		base_url=self.baseURL)
		return oauth_service
Example #21
0
 def __init__(self):
     super(VKProvider, self).__init__('vk')
     self._service = OAuth2Service(
         name='vk',
         client_id=current_app.config['OAUTHS']['vk']['client_id'],
         client_secret=current_app.config['OAUTHS']['vk']['client_secret'],
         authorize_url=current_app.config['OAUTHS']['vk']['authorize_url'],
         access_token_url=current_app.config['OAUTHS']['vk']['token_url'])
Example #22
0
    def setUp(self):
        super(TestRauth, self).setUp()

        self.service = OAuth2Service(
            client_id=self.oauth_client.id,
            client_secret=self.oauth_client.secret,
            authorize_url=reverse("oauth2_authorize"),
        )
Example #23
0
 def __init__(self, client_id, secret, name, authorize_url,
              access_token_url, base_url):
     self.service = OAuth2Service(client_id=client_id,
                                  client_secret=secret,
                                  name=name,
                                  authorize_url=authorize_url,
                                  access_token_url=access_token_url,
                                  base_url=base_url)
 def set_up_service(self):
     self.qbService = OAuth2Service(
         name=None,
         client_id=self.client_id,
         client_secret=self.client_secret,
         access_token_url=self.access_token_url,
         authorize_url=self.authorize_url,
         base_url=None
     )
Example #25
0
 def __init__(self):
     super(GitHubSignIn, self).__init__('github')
     self.service = OAuth2Service(
         name='github',
         client_id=self.consumer_id,
         client_secret=self.consumer_secret,
         authorize_url='https://github.com/login/oauth/authorize',
         access_token_url='https://github.com/login/oauth/access_token',
         base_url='https://github.com/')
Example #26
0
 def __init__(self):
     super(MattermostSignIn, self).__init__('mattermost')
     self.service = OAuth2Service(
         name='mattermost',
         client_id=self.consumer_id,
         client_secret=self.consumer_secret,
         authorize_url=f'{self.base_url}/oauth/authorize',
         access_token_url=f'{self.base_url}/oauth/access_token',
         base_url=self.base_url)
Example #27
0
 def __init__(self):
     super(GoogleSignIn, self).__init__('google')
     self.service = OAuth2Service(
         name='google',
         client_id=self.consumer_id,
         client_secret=self.consumer_secret,
         authorize_url='https://accounts.google.com/o/oauth2/v2/auth',
         access_token_url='https://oauth2.googleapis.com/token',
         base_url='https://openidconnect.googleapis.com/v1/')
Example #28
0
 def __init__(self):
     self.session = None
     self.oauth = OAuth2Service(
         name='spotify',
         base_url='https://api.spotify.com/v1',
         client_id=os.environ['SPOTIFY_CLIENT_ID'],
         client_secret=os.environ['SPOTIFY_CLIENT_SECRET'],
         authorize_url='https://accounts.spotify.com/authorize',
         access_token_url='https://accounts.spotify.com/api/token')
Example #29
0
 def __init__(self, app):
     self.service = OAuth2Service(
         name=self.service_name,
         base_url='https://www.googleapis.com',
         access_token_url='https://accounts.google.com/o/oauth2/token',
         authorize_url='https://accounts.google.com/o/oauth2/auth',
         client_id=app.config['GOOGLE_CONSUMER'][0],
         client_secret=app.config['GOOGLE_CONSUMER'][1])
     super(GoogleOAuth, self).__init__()
Example #30
0
 def __init__(self):
     super(LinkedInSignIn, self).__init__('linkedin')
     self.service = OAuth2Service(
         name='linkedin',
         client_id=self.consumer_id,
         client_secret=self.consumer_secret,
         authorize_url='https://www.linkedin.com/uas/oauth2/authorization',
         access_token_url='https://www.linkedin.com/uas/oauth2/accessToken',
         base_url='https://www.linkedin.com/')
Example #31
0
 def __init__(self):
     super(RedditSignIn, self).__init__('reddit')
     self.service = OAuth2Service(
         name='reddit',
         client_id=self.consumer_id,
         client_secret=self.consumer_secret,
         access_token_url="https://ssl.reddit.com/api/v1/access_token",
         authorize_url="https://ssl.reddit.com/api/v1/authorize",
         base_url='https://api.reddit.com/')
Example #32
0
 def __init__(self, *args):
     super(OAuthGoogle, self).__init__('google', *args)
     self.service = OAuth2Service(
         name='google',
         client_id=self.client_id,
         client_secret=self.client_secret,
         authorize_url='https://accounts.google.com/o/oauth2/v2/auth',
         access_token_url='https://www.googleapis.com/oauth2/v4/token',
         base_url='https://www.googleapis.com/oauth2/v3/')
Example #33
0
 def __init__(self, *args):
     super(OAuthFacebook, self).__init__('facebook', *args)
     self.service = OAuth2Service(
         name='facebook',
         client_id=self.client_id,
         client_secret=self.client_secret,
         authorize_url='https://graph.facebook.com/oauth/authorize',
         access_token_url='https://graph.facebook.com/oauth/access_token',
         base_url='https://graph.facebook.com/')
Example #34
0
    def __init__(self, client_id, client_secret, redirect_uri):
        self.outh_service = OAuth2Service(client_id=client_id,
                                          client_secret=client_secret,
                                          name='linkedin',
                                          authorize_url=AUTHORIZE_URL,
                                          access_token_url=ACCESS_TOKEN,
                                          base_url=BASE_URL)

        self.redirect_uri = redirect_uri
Example #35
0
 def __init__(self):
     super(MLHSignIn, self).__init__('mlh')
     self.service = OAuth2Service(
         name='mlh',
         client_id=self.consumer_id,
         client_secret=self.consumer_secret,
         authorize_url='https://my.mlh.io/oauth/authorize',
         access_token_url='https://my.mlh.io/oauth/token',
         base_url='https://my.mlh.io/')
Example #36
0
 def __init__(self, current_app):
     google_params = self._get_google_info()
     self.service = OAuth2Service(
         name='google',
         client_id=current_app.config['GOOGLE_LOGIN_CLIENT_ID'],
         client_secret=current_app.config['GOOGLE_LOGIN_CLIENT_SECRET'],
         authorize_url=google_params.get('authorization_endpoint'),
         base_url=google_params.get('userinfo_endpoint'),
         access_token_url=google_params.get('token_endpoint'))
Example #37
0
 def get_authorize_url(self, **params):
     params.setdefault("response_type", "code")
     params.setdefault("redirect_uri", self.redirect_uri)
     params.setdefault("scope", "user:email")
     return OAuth2Service.get_authorize_url(self, **params)
Example #38
0
 def get_auth_session(self, **kwargs):
     if 'data' in kwargs and isinstance(kwargs['data'], dict):
         kwargs['data'].setdefault('redirect_uri', self.redirect_uri)
     return OAuth2Service.get_auth_session(self, **kwargs)
Example #39
0
 def get_authorize_url(self, **params):
     params.setdefault('response_type', 'code')
     params.setdefault('redirect_uri', self.redirect_uri)
     params.setdefault('scope', 'user:email')
     return OAuth2Service.get_authorize_url(self, **params)
Example #40
0
 def get_auth_session(self, **kwargs):
     if "data" in kwargs and isinstance(kwargs["data"], dict):
         kwargs["data"].setdefault("redirect_uri", self.redirect_uri)
         kwargs["data"].setdefault("grant_type", "authorization_code")
     return OAuth2Service.get_auth_session(self, **kwargs)
Example #41
0
 def get_auth_session(self, **kwargs):
     if 'data' in kwargs and isinstance(kwargs['data'], dict):
         kwargs['data'].setdefault('redirect_uri', self.redirect_uri)
         kwargs['data'].setdefault('grant_type', 'authorization_code')
     return OAuth2Service.get_auth_session(self, **kwargs)
Example #42
0
 def get_auth_session(self, **kwargs):
     if "data" in kwargs and isinstance(kwargs["data"], dict):
         kwargs["data"].setdefault("redirect_uri", self.redirect_uri)
     return OAuth2Service.get_auth_session(self, **kwargs)