Get an auth token from the auth provider with the given key. If successful, the result will be cached on this auth context. If unsuccessful, nothing will be cached, so a future call will invoke the underlying `AuthProvider.authenticate` method again. This method is
(self, provider_key)
| 73 | return cls({}, {}) |
| 74 | |
| 75 | def get(self, provider_key): |
| 76 | """Get an auth token from the auth provider with the given key. |
| 77 | |
| 78 | If successful, the result will be cached on this auth context. |
| 79 | If unsuccessful, nothing will be cached, so a future call will |
| 80 | invoke the underlying `AuthProvider.authenticate` method again. |
| 81 | |
| 82 | This method is not thread-safe. If multiple threads share an |
| 83 | auth context for a single request, then they must synchronize |
| 84 | externally when calling this method. |
| 85 | |
| 86 | Returns: |
| 87 | The result of `provider.authenticate(...)` for the auth |
| 88 | provider specified by `provider_key`. |
| 89 | |
| 90 | Raises: |
| 91 | KeyError: If the given `provider_key` does not correspond to |
| 92 | any registered `AuthProvider`. |
| 93 | Exception: As raised by the underlying `AuthProvider`. |
| 94 | """ |
| 95 | provider = self._providers[provider_key] |
| 96 | sentinel = object() |
| 97 | value = self._cache.get(provider_key, sentinel) |
| 98 | if value is not sentinel: |
| 99 | return value |
| 100 | value = provider.authenticate(self._environ) |
| 101 | self._cache[provider_key] = value |
| 102 | return value |