import json


def get_secrets_from_json(provider_name, filename):
    """
    Reads the providers client_secrets.json file

    Args:
        provider_name: string, OAuth2 provider (Google, Facebook)
        filename: string, File name of client secrets.
    Returns:
        id, secret: string
    """
    id, secret = None, None
    try:
        with open(filename, 'r', encoding='utf-8') as f:
            json_object = json.load(f)
            # print(json_object)
            if provider_name == 'google':
                id = json_object['web'].get('client_id')
                secret = json_object['web'].get('client_secret')
            elif provider_name == 'facebook':
                id = json_object['web'].get('app_id')
                secret = json_object['web'].get('app_secret')
            else:
                print('Unknown provider for get_secrets_from_json')
    except FileNotFoundError:
        print('Unknown client_secrets.json file')

    return id, secret