当前位置: 首页>>代码示例>>Python>>正文


Python AppAssertionCredentials.authorize方法代码示例

本文整理汇总了Python中oauth2client.contrib.appengine.AppAssertionCredentials.authorize方法的典型用法代码示例。如果您正苦于以下问题:Python AppAssertionCredentials.authorize方法的具体用法?Python AppAssertionCredentials.authorize怎么用?Python AppAssertionCredentials.authorize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oauth2client.contrib.appengine.AppAssertionCredentials的用法示例。


在下文中一共展示了AppAssertionCredentials.authorize方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: hello

# 需要导入模块: from oauth2client.contrib.appengine import AppAssertionCredentials [as 别名]
# 或者: from oauth2client.contrib.appengine.AppAssertionCredentials import authorize [as 别名]
def hello():

    credentials = AppAssertionCredentials([])
    client = datastore.Client(project = 'mq-cloud-prototyping-3', credentials = credentials)
    sys.stdout.write(credentials.to_json())
    
    query = client.query(kind='Person')
    res = query.fetch()
    all = dict(res)
    sys.stdout.write(str(all))
    
    return credentials.to_json()

    try :        
    	
    	token = ''

    	#ouath
        O_AUTH_EMAIL_SCOPE = 'https://www.googleapis.com/auth/userinfo.email'

        credentials = GoogleCredentials.get_application_default()
        if credentials.create_scoped_required():
	        credentials = credentials.create_scoped(PUBSUB_SCOPES)
        http = httplib2.Http()
        credentials.authorize(http)

        cl = discovery.build('pubsub', 'v1', http=http)
        return credentials.to_json()

        credentials = GoogleCredentials.get_application_default()
        credentials = credentials.create_scoped([O_AUTH_EMAIL_SCOPE])
      	http = httplib2.Http()
    	credentials.authorize(http)
        return credentials.to_json()
	    #if not http:
	    #    http = httplib2.Http()
	    #credentials.authorize(http)

    	#temp hardcoded token
        #token = 'ya29.CjjlAlrvqUwXrujCnJuqa08HTtmNilyP7K1GGrHQ40Gt489H6NGT9WQAxEL92OSQ6anGYeFPRcvI4g'

        



        tokenBearer = 'Bearer %s' % token
        url = 'https://admin-dot-mq-vouchers.appspot.com/api/communities/mtv1/campaigns?page=0&size=1000&sorting=campaignName,ASC'
        req = urllib2.Request(url, headers = {'Content-Type': 'application/json', 'Authorization' : tokenBearer})
        f = urllib2.urlopen(req)
        response = f.read()
        sys.stdout.write(str(response))
        respjson = json.loads(response)
        
        f.close()
        #respjson = '3333'
        #sys.stdout.write(str(all))
        return str(response)
    except urllib2.HTTPError, error:
    	return ('get failed %s' % error)
开发者ID:neilmca,项目名称:gc_flexible_runtime_experminent,代码行数:61,代码来源:main.py

示例2: get

# 需要导入模块: from oauth2client.contrib.appengine import AppAssertionCredentials [as 别名]
# 或者: from oauth2client.contrib.appengine.AppAssertionCredentials import authorize [as 别名]
  def get(self):
      scope = 'https://www.googleapis.com/auth/userinfo.email'
      credentials = AppAssertionCredentials(scope)
      http = credentials.authorize(Http())

      DISCOVERY_URL = (
        'https://monorail-prod.appspot.com/_ah/api/discovery/v1/apis/'
        '{api}/{apiVersion}/rest'
      )

      monorail = build(
        'monorail', 'v1',
        discoveryServiceUrl=DISCOVERY_URL,
        http=http
      )
      if self.request.get('site') == 'issues':
          urlfetch.set_default_fetch_deadline(10)
          self.response.headers.add_header("Access-Control-Allow-Origin", "*")
          result = monorail.issues().list(projectId='chromium', q=self.request.get('q'), can='open').execute()
          self.response.write(json.dumps(result))
      elif self.request.get('site') == 'issue':
          urlfetch.set_default_fetch_deadline(10)
          self.response.headers.add_header("Access-Control-Allow-Origin", "*")
          result = monorail.issues().get(projectId='chromium', issueId=self.request.get('issueId')).execute()
          self.response.write(json.dumps(result))
      elif self.request.get('site') == 'comments':
          urlfetch.set_default_fetch_deadline(10)
          self.response.headers.add_header("Access-Control-Allow-Origin", "*")
          result = monorail.issues().comments().list(projectId='chromium', issueId=self.request.get('issueId')).execute()
          self.response.write(json.dumps(result))
开发者ID:ewilligers,项目名称:chromez,代码行数:32,代码来源:redirect.py

示例3: get

# 需要导入模块: from oauth2client.contrib.appengine import AppAssertionCredentials [as 别名]
# 或者: from oauth2client.contrib.appengine.AppAssertionCredentials import authorize [as 别名]
  def get(self):
      if self.request.get('site') == 'issues':
          url = "https://bugs.chromium.org/p/chromium/issues/csv?"
          for item in self.request.GET.items():
              if item[0] != 'site':
                  url += item[0] +'=' + item[1] + '&'
          scope = 'https://www.googleapis.com/auth/userinfo.email'
          credentials = AppAssertionCredentials(scope)
          http = credentials.authorize(Http())

          DISCOVERY_URL = (
            'https://monorail-prod.appspot.com/_ah/api/discovery/v1/apis/'
            '{api}/{apiVersion}/rest'
          )

          monorail = build(
            'monorail', 'v1',
            discoveryServiceUrl=DISCOVERY_URL,
            http=http
          )

          urlfetch.set_default_fetch_deadline(10)
          self.response.headers.add_header("Access-Control-Allow-Origin", "*")
          result = monorail.issues().list(projectId='chromium', owner=self.request.get('q')[6:], can='open').execute()
          self.response.write(json.dumps(result))
开发者ID:nainar,项目名称:chromez,代码行数:27,代码来源:redirect.py

示例4: generate_jwt

# 需要导入模块: from oauth2client.contrib.appengine import AppAssertionCredentials [as 别名]
# 或者: from oauth2client.contrib.appengine.AppAssertionCredentials import authorize [as 别名]
def generate_jwt():
    """Generates a signed JSON Web Token using a service account."""
    credentials = AppAssertionCredentials(
        'https://www.googleapis.com/auth/iam')
    http_auth = credentials.authorize(httplib2.Http())
    service = googleapiclient.discovery.build(
        serviceName='iam', version='v1', http=http_auth)

    now = int(time.time())

    header_json = json.dumps({
        "typ": "JWT",
        "alg": "RS256"})

    payload_json = json.dumps({
        'iat': now,
        # expires after one hour.
        "exp": now + 3600,
        # iss is the service account email.
        'iss': SERVICE_ACCOUNT_EMAIL,
        'sub': SERVICE_ACCOUNT_EMAIL,
        # aud must match 'audience' in the security configuration in your
        # swagger spec.It can be any string.
        'aud': 'echo.endpoints.sample.google.com',
        "email": SERVICE_ACCOUNT_EMAIL
    })

    headerAndPayload = '{}.{}'.format(
        base64.urlsafe_b64encode(header_json),
        base64.urlsafe_b64encode(payload_json))
    slist = service.projects().serviceAccounts().signBlob(
        name=SERVICE_ACCOUNT,
        body={'bytesToSign': base64.b64encode(headerAndPayload)})
    res = slist.execute()
    signature = base64.urlsafe_b64encode(
        base64.decodestring(res['signature']))
    signed_jwt = '{}.{}'.format(headerAndPayload, signature)

    return signed_jwt
开发者ID:Paul171,项目名称:python-docs-samples,代码行数:41,代码来源:main.py

示例5: generate_jwt

# 需要导入模块: from oauth2client.contrib.appengine import AppAssertionCredentials [as 别名]
# 或者: from oauth2client.contrib.appengine.AppAssertionCredentials import authorize [as 别名]
def generate_jwt():
    """Generates a signed JSON Web Token using a service account."""
    credentials = AppAssertionCredentials("https://www.googleapis.com/auth/iam")
    http_auth = credentials.authorize(httplib2.Http())
    service = build(serviceName="iam", version="v1", http=http_auth)

    now = int(time.time())

    header_json = json.dumps({"typ": "JWT", "alg": "RS256"})

    payload_json = json.dumps(
        {
            "iat": now,
            # expires after one hour.
            "exp": now + 3600,
            # iss is the service account email.
            "iss": SERVICE_ACCOUNT_EMAIL,
            "sub": SERVICE_ACCOUNT_EMAIL,
            # aud must match 'audience' in the security configuration in your
            # swagger spec.It can be any string.
            "aud": "echo.endpoints.sample.google.com",
            "email": SERVICE_ACCOUNT_EMAIL,
        }
    )

    headerAndPayload = "{}.{}".format(base64.urlsafe_b64encode(header_json), base64.urlsafe_b64encode(payload_json))
    slist = (
        service.projects()
        .serviceAccounts()
        .signBlob(name=SERVICE_ACCOUNT, body={"bytesToSign": base64.b64encode(headerAndPayload)})
    )
    res = slist.execute()
    signature = base64.urlsafe_b64encode(base64.decodestring(res["signature"]))
    signed_jwt = "{}.{}".format(headerAndPayload, signature)

    return signed_jwt
开发者ID:WalterHub,项目名称:python-docs-samples,代码行数:38,代码来源:main.py

示例6: get

# 需要导入模块: from oauth2client.contrib.appengine import AppAssertionCredentials [as 别名]
# 或者: from oauth2client.contrib.appengine.AppAssertionCredentials import authorize [as 别名]
    def get(self):

        credentials = AppAssertionCredentials("https://www.googleapis.com/auth/calendar.readonly")
        http_auth = credentials.authorize(Http())
        cal_service = discovery.build('calendar', 'v3', http=http_auth)

        service_settings = ServiceSettings.query().get()
        if not service_settings:
            service_settings = ServiceSettings()
        next_sync_token = service_settings.cal_sync_token

        cal_events = []
        if next_sync_token:
            now = None
        else:
            now = strict_rfc3339.now_to_rfc3339_utcoffset()

        try:
            events_result = cal_service.events().list(calendarId="[email protected]", timeMin=now,
                                                      syncToken=next_sync_token).execute()
        except:
            service_settings.cal_sync_token = None
            service_settings.put()
            raise

        cal_events += events_result.get('items', [])
        next_page_token = events_result.get('nextPageToken', None)

        while next_page_token:
            events_result = cal_service.events().list(calendarId="[email protected]", timeMin=now,
                                                      syncToken=next_sync_token, pageToken=next_page_token).execute()
            cal_events += events_result.get('items', [])
            next_page_token = events_result.get('nextPageToken', None)

        next_sync_token = events_result.get("nextSyncToken", None)
        service_settings.cal_sync_token = next_sync_token
        service_settings.put()

        for cal_event in cal_events:
            cal_id = cal_event.get("id")

            event = Event.query().filter(Event.cal_id == cal_id).get()

            if event:
                q = taskqueue.Queue('default')
                for task in event.tasks:
                    q.delete_tasks(taskqueue.Task(name=task))
                event.tasks = []

                if cal_event.get("status") == "cancelled":
                    event.key.delete()
                    logging.info("Event deleted: %s", event)
                    continue
            else:
                event = Event(cal_id=cal_id)
                event.put()

            summary = cal_event.get("summary")
            description = cal_event.get("description")

            start = cal_event.get("start")
            end = cal_event.get("end")

            start = parse_date_time(start.get("date"), start.get("dateTime"))
            end = parse_date_time(end.get("date"), end.get("dateTime"))

            event.summary = summary
            event.description = description
            event.start = start
            event.end = end

            set_event_reminders(event)

            event.put()

            logging.info("New event created: %s", event)
开发者ID:shawnaten,项目名称:spectrum-sms,代码行数:78,代码来源:calendar_handler.py

示例7: AppAssertionCredentials

# 需要导入模块: from oauth2client.contrib.appengine import AppAssertionCredentials [as 别名]
# 或者: from oauth2client.contrib.appengine.AppAssertionCredentials import authorize [as 别名]
import re

from google.appengine.api import memcache
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
from oauth2client.contrib.appengine import AppAssertionCredentials

# Constants for the XSL stylesheet and the Google Cloud Storage URI.
XSL = '\n<?xml-stylesheet href="/listing.xsl" type="text/xsl"?>\n';
URI = 'http://commondatastorage.googleapis.com'

# Obtain service account credentials and authorize HTTP connection.
credentials = AppAssertionCredentials(
    scope='https://www.googleapis.com/auth/devstorage.read_write')
http = credentials.authorize(httplib2.Http(memcache))


class MainHandler(webapp.RequestHandler):

  def get(self):
    try:
      # Derive desired bucket name from path after domain name.
      bucket = self.request.path
      if bucket[-1] == '/':
        # Trim final slash, if necessary.
        bucket = bucket[:-1]
      # Send HTTP request to Google Cloud Storage to obtain bucket listing.
      resp, content = http.request(URI + bucket, "GET")
      if resp.status != 200:
        # If error getting bucket listing, raise exception.
开发者ID:343829084,项目名称:google-api-python-client,代码行数:33,代码来源:main.py

示例8: get_credentials

# 需要导入模块: from oauth2client.contrib.appengine import AppAssertionCredentials [as 别名]
# 或者: from oauth2client.contrib.appengine.AppAssertionCredentials import authorize [as 别名]
def get_credentials():
    """Authorizes a request to Google Cloud Platform."""
    credentials = AppAssertionCredentials(
        'https://www.googleapis.com/auth/cloud-platform')
    http_auth = credentials.authorize(Http())
    return build('compute', 'v1', http=http_auth)
开发者ID:rhefner1,项目名称:notebook-versioner,代码行数:8,代码来源:nv_control.py

示例9: auth_bq

# 需要导入模块: from oauth2client.contrib.appengine import AppAssertionCredentials [as 别名]
# 或者: from oauth2client.contrib.appengine.AppAssertionCredentials import authorize [as 别名]
 def auth_bq(self):
     credentials = AppAssertionCredentials(scope=SCOPE)
     http = credentials.authorize(httplib2.Http())
     bigquery = build('bigquery', 'v2', http=http)
     return bigquery
开发者ID:noralife,项目名称:gcp-export-billing-bq,代码行数:7,代码来源:cron.py


注:本文中的oauth2client.contrib.appengine.AppAssertionCredentials.authorize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。