def _magic_number(self, request, form): """ A super secret grant flow that gives an access token for 'magic' application if you guess the right number. """ from fulmine.models import build_access_token from fulmine.views import OAuth2Error client_id = "magic" if form.cleaned_data["magic_number"] == "42": access_token = build_access_token(client_id=client_id, expires_in=self.expires_in(None), scope=[]) return dict( token_type="bearer", access_token=access_token, refresh_token=None, expires_in=self.expires_in(None) ) else: raise OAuth2Error("invalid_grant")
def _client_credentials(self, request, form): client_id = self.client_for_request(request, None) if not client_id: return OAuth2Error('invalid_client') scope = self.limit_scope(client_id, form.cleaned_data['scope']) expires_in = self.expires_in(None) access_token = build_access_token( client_id=client_id, expires_in=expires_in, scope=scope, ) return dict( access_token=access_token, token_type='bearer', expires_in=expires_in, refresh_token=None, scope=scope, )