@@ -31,16 +31,74 @@ class Auth:
3131
3232 :type requests: :class:`~requests.Session`
3333 :param requests: Session to make HTTP requests
34+
35+ :type client_secret: str or dict
36+ :param client_secret: (Optional) Dict object from social client
37+ secret file, defaults to :data:`None`.
3438 """
3539
36- def __init__ (self , api_key , credentials , requests ):
40+ def __init__ (self , api_key , credentials , requests , client_secret = None ):
3741 """ Constructor method """
3842
3943 self .api_key = api_key
4044 self .credentials = credentials
4145 self .requests = requests
4246
4347 self .current_user = None
48+ self .provider_id = None
49+ self .session_id = None
50+
51+ if client_secret :
52+ self .client_secret = client_secret
53+
54+ def create_authentication_uri (self , provider_id ):
55+ """ Creates an authentication URI for the given social
56+ provider.
57+
58+ | For more details:
59+ | |section-fetch-providers-for-email|_
60+
61+ .. |section-fetch-providers-for-email| replace::
62+ Firebase Auth REST API | Fetch providers for email
63+
64+ .. _section-fetch-providers-for-email:
65+ https://firebase.google.com/docs/reference/rest/auth#section-fetch-providers-for-email
66+
67+
68+ :type provider_id: str
69+ :param provider_id: The IdP ID. For white listed IdPs it's a
70+ short domain name e.g. 'google.com', 'aol.com', 'live.net'
71+ and 'yahoo.com'. For other OpenID IdPs it's the OP
72+ identifier.
73+
74+
75+ :return: The URI used by the IDP to authenticate the user.
76+ :rtype: str
77+ """
78+
79+ request_ref = "https://www.googleapis.com/identitytoolkit/v3/relyingparty/createAuthUri?key={0}" .format (self .api_key )
80+
81+ data = {
82+ "authFlowType" : 'CODE_FLOW' ,
83+ "clientId" : self .client_secret ['client_id' ],
84+ "providerId" : provider_id ,
85+ "continueUri" : self .client_secret ['redirect_uris' ][0 ],
86+ "customParameter" : {
87+ "access_type" : 'offline' ,
88+ "prompt" : 'select_account' ,
89+ "include_granted_scopes" : 'true' ,
90+ }
91+ }
92+
93+ headers = {"content-type" : "application/json; charset=UTF-8" }
94+ request_object = self .requests .post (request_ref , headers = headers , json = data )
95+
96+ raise_detailed_error (request_object )
97+
98+ self .provider_id = provider_id
99+ self .session_id = request_object .json ()['sessionId' ]
100+
101+ return request_object .json ()['authUri' ]
44102
45103 def sign_in_with_email_and_password (self , email , password ):
46104 """ Sign in a user with an email and password.
0 commit comments