示例#1
0
def create_login_url(dest_url, _auth_domain=None):
    """Computes the login URL for this request and specified destination URL.

  Args:
    dest_url: String that is the desired final destination URL for the user
              once login is complete. If 'dest_url' does not have a host
              specified, we will use the host from the current request.

  Returns:
    string
  """
    req = user_service_pb.CreateLoginURLRequest()
    resp = user_service_pb.CreateLoginURLResponse()
    req.set_destination_url(dest_url)
    if _auth_domain:
        req.set_auth_domain(_auth_domain)

    try:
        apiproxy_stub_map.MakeSyncCall('user', 'CreateLoginURL', req, resp)
    except apiproxy_errors.ApplicationError, e:
        if (e.application_error ==
                user_service_pb.UserServiceError.REDIRECT_URL_TOO_LONG):
            raise RedirectTooLongError
        elif (e.application_error ==
              user_service_pb.UserServiceError.NOT_ALLOWED):
            raise NotAllowedError
        else:
            raise e
示例#2
0
def create_login_url(dest_url=None,
                     _auth_domain=None,
                     federated_identity=None):
    """Computes the login URL for redirection.

  Args:
    dest_url: String that is the desired final destination URL for the user
        once login is complete. If `dest_url` does not specify a host, the host
        from the current request is used.
    federated_identity: Decommissioned, don't use. Setting this to a non-None
        value raises a NotAllowedError

  Returns:
       Login URL as a string. The login URL will use Google Accounts.

  Raises:
      NotAllowedError: If federated_identity is not None.
  """
    req = user_service_pb.CreateLoginURLRequest()
    resp = user_service_pb.CreateLoginURLResponse()
    if dest_url:
        req.set_destination_url(dest_url)
    else:
        req.set_destination_url('')
    if _auth_domain:
        req.set_auth_domain(_auth_domain)
    if federated_identity:
        raise NotAllowedError('OpenID 2.0 support is decomissioned')

    try:
        apiproxy_stub_map.MakeSyncCall('user', 'CreateLoginURL', req, resp)
    except apiproxy_errors.ApplicationError as e:
        if (e.application_error ==
                user_service_pb.UserServiceError.REDIRECT_URL_TOO_LONG):
            raise RedirectTooLongError
        elif (e.application_error ==
              user_service_pb.UserServiceError.NOT_ALLOWED):
            raise NotAllowedError
        else:
            raise e
    return resp.login_url()
示例#3
0
def create_login_url(dest_url=None,
                     _auth_domain=None,
                     federated_identity=None):
    """Computes the login URL for redirection.

  Args:
    dest_url: String that is the desired final destination URL for the user
              once login is complete. If 'dest_url' does not have a host
              specified, we will use the host from the current request.
    federated_identity: federated_identity is used to trigger OpenId Login
                        flow, an empty value will trigger Google OpenID Login
                        by default.

  Returns:
       Login URL as a string. If federated_identity is set, this will be
       a federated login using the specified identity. If not, this
       will use Google Accounts.
  """
    req = user_service_pb.CreateLoginURLRequest()
    resp = user_service_pb.CreateLoginURLResponse()
    if dest_url:
        req.set_destination_url(dest_url.encode())
    else:
        req.set_destination_url(b'')
    if _auth_domain:
        req.set_auth_domain(_auth_domain.encode())
    if federated_identity:
        req.set_federated_identity(federated_identity.encode())

    try:
        apiproxy_stub_map.MakeSyncCall('user', 'CreateLoginURL', req, resp)
    except apiproxy_errors.ApplicationError as e:
        if (e.application_error ==
                user_service_pb.UserServiceError.REDIRECT_URL_TOO_LONG):
            raise RedirectTooLongError
        elif (e.application_error ==
              user_service_pb.UserServiceError.NOT_ALLOWED):
            raise NotAllowedError
        else:
            raise e
    return resp.login_url().decode()
def create_login_url(dest_url=None,
                     _auth_domain=None,
                     federated_identity=None):
    """Computes the login URL for redirection.

  Args:
    dest_url: String that is the desired final destination URL for the user
        once login is complete. If `dest_url` does not specify a host, the host
        from the current request is used.
    federated_identity: Triggers an OpenID login flow. If `federated_identity`
        is not specified, Google OpenID login will be used.

  Returns:
       Login URL as a string. If `federated_identity` is set, the returned
       string represents a federated login that uses the specified identity. If
       `federated_identity` is not set, the login URL will use Google Accounts.
  """
    req = user_service_pb.CreateLoginURLRequest()
    resp = user_service_pb.CreateLoginURLResponse()
    if dest_url:
        req.set_destination_url(dest_url)
    else:
        req.set_destination_url('')
    if _auth_domain:
        req.set_auth_domain(_auth_domain)
    if federated_identity:
        req.set_federated_identity(federated_identity)

    try:
        apiproxy_stub_map.MakeSyncCall('user', 'CreateLoginURL', req, resp)
    except apiproxy_errors.ApplicationError, e:
        if (e.application_error ==
                user_service_pb.UserServiceError.REDIRECT_URL_TOO_LONG):
            raise RedirectTooLongError
        elif (e.application_error ==
              user_service_pb.UserServiceError.NOT_ALLOWED):
            raise NotAllowedError
        else:
            raise e