コード例 #1
0
 def test_required_field(self, key):
     data = {
         'client_id': 'value',
         'client_secret': 'value',
         'refresh_token': 'value',
         'type': 'authorized_user'
     }
     del data[key]
     with pytest.raises(ValueError):
         credentials.RefreshToken(data)
コード例 #2
0
    def test_init_from_file(self):
        credential = credentials.RefreshToken(
            testutils.resource_filename('refresh_token.json'))
        assert credential.client_id == 'mock.apps.googleusercontent.com'
        assert credential.client_secret == 'mock-secret'
        assert credential.refresh_token == 'mock-refresh-token'

        g_credential = credential.get_credential()
        assert isinstance(g_credential, gcredentials.Credentials)
        assert g_credential.token is None
        check_scopes(g_credential)

        mock_response = {
            'access_token': 'mock_access_token',
            'expires_in': 3600
        }
        credentials._request = testutils.MockRequest(200, json.dumps(mock_response))
        access_token = credential.get_access_token()
        assert access_token.access_token == 'mock_access_token'
        assert isinstance(access_token.expiry, datetime.datetime)
コード例 #3
0
ファイル: fcm.py プロジェクト: sn94/uvSkin
 def send_a_notification_sdk_admin(self, title, body, token):
     registration_token = token
     # See documentation on defining a message payload.
     import firebase_admin
     from firebase_admin import credentials
     from firebase_admin import messaging
     cred = credentials.RefreshToken(
         'uvapp-246400-04d67e9d0c21firebasecount.json')
     #cred = credentials.Certificate('mensajeador-5822102cebdc.json')
     app = firebase_admin.initialize_app(cred)
     a_notification = messaging.Notification(title=title, body=body)
     message = messaging.Message(
         data=None,
         notification=a_notification,
         token=registration_token,
     )
     # Send a message to the device corresponding to the provided
     # registration token.
     response = messaging.send(message)
     # Response is a message ID string.
     print('Successfully sent message:', response)
     firebase_admin.delete_app(app)  #borrar instancia anterior
コード例 #4
0
def initialize_sdk_with_refresh_token():
    # [START initialize_sdk_with_refresh_token]
    cred = credentials.RefreshToken('path/to/refreshToken.json')
    default_app = firebase_admin.initialize_app(cred)
    # [END initialize_sdk_with_refresh_token]
    firebase_admin.delete_app(default_app)
コード例 #5
0
 def test_invalid_args(self, arg):
     with pytest.raises(ValueError):
         credentials.RefreshToken(arg)
コード例 #6
0
 def test_init_from_invalid_file(self):
     with pytest.raises(ValueError):
         credentials.RefreshToken(
             testutils.resource_filename('service_account.json'))
コード例 #7
0
 def test_init_from_nonexisting_file(self):
     with pytest.raises(IOError):
         credentials.RefreshToken(
             testutils.resource_filename('non_existing.json'))
コード例 #8
0
 def test_init_from_dict(self):
     parsed_json = json.loads(testutils.resource('refresh_token.json'))
     credential = credentials.RefreshToken(parsed_json)
     self._verify_credential(credential)
コード例 #9
0
 def test_init_from_file(self):
     credential = credentials.RefreshToken(
         testutils.resource_filename('refresh_token.json'))
     self._verify_credential(credential)
コード例 #10
0
 def get(self):
     return credentials.RefreshToken(
         testutils.resource_filename('refresh_token.json'))
コード例 #11
0
ファイル: leveldbHA.py プロジェクト: pmgexpo17/ApiServicePeer
 def make(cls, projectId, jobId):
     credPath = f'{cls.projectBase}/{projectId}-firebase-credentials.json'
     cred = credentials.RefreshToken(credPath)
     cls.fbApp = firebase_admin.initialize_app(cred)
     return cls(jobId)
コード例 #12
0
import firebase_admin
from firebase_admin import auth
from firebase_admin import messaging
from firebase_admin import credentials

# This registration token comes from the client FCM SDKs.
registration_token = 'ccf1-MwxPDA:APA91bFCmxFzOVz4C5BcoJS_WObG4OuUwUwAlBkSSfmGRtC7PBFf4PAbF5tabqe0kQzy8KSc201vJcFCZQpgQu_Am6-cl1FvdzfbVn__G9QqBSPlv7pnOCONRM_9gz1QWtYLFLzcrGsK'

cred = credentials.RefreshToken('service-account-file.json')
default_app = firebase_admin.initialize_app(cred)
# See documentation on defining a message payload.
message = messaging.Message(
    data={
        'score': '850',
        'time': '2:45',
    },
    token=registration_token,
)

# Send a message to the device corresponding to the provided
# registration token.
response = messaging.send(message)
# Response is a message ID string.
print('Successfully sent message:', response)

コード例 #13
0
 def test_init_from_path_like(self):
     path = pathlib.Path(testutils.resource_filename('refresh_token.json'))
     credential = credentials.RefreshToken(path)
     self._verify_credential(credential)