# Path: accounts/models.py
# class ServiceCredentials(models.Model):
#     """
#     This model is intended to store the credentials returned by a service after
#     an Audio Commons account is linked with it. Credentials are intentionally
#     stored in a JSONField to accommodate different types of credentials returned
#     by services. The ACServiceBase authentication methods will be in charge of
#     interpreting the contests of the 'credentials' field.
#     """
# 
#     account = models.ForeignKey(Account, related_name='service_credentials')
#     service_id = models.CharField(max_length=64)
#     credentials = JSONField(null=False, default={})
#     created = models.DateTimeField(auto_now_add=True)
#     modified = models.DateTimeField(auto_now=True)
# 
#     class Meta:
#         verbose_name = _('service credentials')
#         verbose_name_plural = _('service credentials')
#         unique_together = (('account', 'service_id'),)
# 
#     def __str__(self):
#         return 'ServiceCredentials for {0} and {1}'.format(self.account.username, self.service_id)


from accounts.models import ServiceCredentials
from ac_mediator.exceptions import *
from django.core.urlresolvers import reverse
from django.conf import settings
from services.acservice.constants import *
import requests
    def get_authorize_popup_specs():
        return 'height=400,width=500'

    @staticmethod
    def process_credentials(credentials_data):
        return credentials_data

    def supports_auth(self, auth_type):
        return auth_type in self.SUPPORTED_AUTH_METHODS

    def get_apikey(self):
        """
        API key used for non-end user authenticated requests
        TODO: this should include the way in which the api key is included (via header, request param, etc)
        :return: string containing the api key
        """
        if not self.supports_auth(APIKEY_AUTH_METHOD):
            raise ACException('Auth method \'{0}\' not supported by service {0}'.format(APIKEY_AUTH_METHOD, self.name))
        return self.service_client_secret

    def get_enduser_token(self, account):
        """
        Get token used to make requests to the service on behalf of 'account'
        TODO: this should include the way in which the token is included (via header, request param, etc)
        :param account: user account to act on behalf of
        :return: string containing the token
        """
        if not self.supports_auth(ENDUSER_AUTH_METHOD):
            raise ACException('Auth method \'{0}\' not supported by service {1}'.format(ENDUSER_AUTH_METHOD, self.name))
        try:

# Path: accounts/models.py
# class ServiceCredentials(models.Model):
#     """
#     This model is intended to store the credentials returned by a service after
#     an Audio Commons account is linked with it. Credentials are intentionally
#     stored in a JSONField to accommodate different types of credentials returned
#     by services. The ACServiceBase authentication methods will be in charge of
#     interpreting the contests of the 'credentials' field.
#     """
# 
#     account = models.ForeignKey(Account, related_name='service_credentials')
#     service_id = models.CharField(max_length=64)
#     credentials = JSONField(null=False, default={})
#     created = models.DateTimeField(auto_now_add=True)
#     modified = models.DateTimeField(auto_now=True)
# 
#     class Meta:
#         verbose_name = _('service credentials')
#         verbose_name_plural = _('service credentials')
#         unique_together = (('account', 'service_id'),)
# 
#     def __str__(self):
#         return 'ServiceCredentials for {0} and {1}'.format(self.account.username, self.service_id)


# Path: services/acservice/auth.py
from accounts.models import ServiceCredentials
from ac_mediator.exceptions import *
from django.core.urlresolvers import reverse
from django.conf import settings
from services.acservice.constants import *
import requests

    def get_authorize_popup_specs():
        return 'height=400,width=500'

    @staticmethod
    def process_credentials(credentials_data):
        return credentials_data

    def supports_auth(self, auth_type):
        return auth_type in self.SUPPORTED_AUTH_METHODS

    def get_apikey(self):
        """
        API key used for non-end user authenticated requests
        TODO: this should include the way in which the api key is included (via header, request param, etc)
        :return: string containing the api key
        """
        if not self.supports_auth(APIKEY_AUTH_METHOD):
            raise ACException('Auth method \'{0}\' not supported by service {0}'.format(APIKEY_AUTH_METHOD, self.name))
        return self.service_client_secret

    def get_enduser_token(self, account):
        """
        Get token used to make requests to the service on behalf of 'account'
        TODO: this should include the way in which the token is included (via header, request param, etc)
        :param account: user account to act on behalf of
        :return: string containing the token
        """
        if not self.supports_auth(ENDUSER_AUTH_METHOD):
            raise ACException('Auth method \'{0}\' not supported by service {1}'.format(ENDUSER_AUTH_METHOD, self.name))
        try:

            service_credentials = ServiceCredentials.objects.get(account=account, service_id=self.id)