<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def get_async_token(self, context, credentials):
 """Gets access_token in async process :param context: DomainConnectAsyncContext :param credentials: DomainConnectAsyncCredentials :return: DomainConnectAsyncContext context enriched with access_token and refresh_token if existing :raises: AsyncTokenException """

        params = {'code': context.code, 'grant_type': 'authorization_code'}
        if getattr(context, 'iat', None) and getattr(context, 'access_token_expires_in', None) and \
                getattr(context, 'refresh_token', None):
            now = int(time.time()) + 60
            if now > context.iat + context.access_token_expires_in:
                params = {'refresh_token': context.refresh_token, 'grant_type': 'refresh_token',
                          'client_id': credentials.client_id, 'client_secret': credentials.client_secret
                }
            else:
                logger.debug('Context has a valid access token')
                return context
        params['redirect_uri'] = context.return_url

        url_get_access_token = '{}/v2/oauth/access_token?{}'.format(context.config.urlAPI,
                                                                    urllib.parse.urlencode(
                                                                        sorted(params.items(), key=lambda val: val[0])))
        try:
            # this has to be checked to avoid secret leakage by spoofed "settings" end-point
            if credentials.api_url != context.config.urlAPI:
                raise AsyncTokenException("URL API for provider does not match registered one with credentials")
            data, status = http_request_json(self._networkContext,
                                             method='POST',
                                             content_type='application/json',
                                             body=json.dumps({
                                                 'client_id': credentials.client_id,
                                                 'client_secret': credentials.client_secret,
                                             }),
                                             url=url_get_access_token
                                             )
        except Exception as ex:
            logger.debug('Cannot get async token: {}'.format(ex))
            raise AsyncTokenException('Cannot get async token: {}'.format(ex))

        if 'access_token' not in data \
                or 'expires_in' not in data \
                or 'token_type' not in data \
                or data['token_type'].lower() != 'bearer':
            logger.debug('Token not complete: {}'.format(data))
            raise AsyncTokenException('Token not complete: {}'.format(data))

        context.access_token = data['access_token']
        context.access_token_expires_in = data['expires_in']
        context.iat = int(time.time())

        if 'refresh_token' in data:
            context.refresh_token = data['refresh_token']

        return context