@@ -39,7 +39,8 @@ class AuthProvider(AuthProviderBase):
3939 AUTH_SERVER_URL = "https://login.live.com/oauth20_authorize.srf"
4040 AUTH_TOKEN_URL = "https://login.live.com/oauth20_token.srf"
4141
42- def __init__ (self , http_provider , client_id = None , scopes = None , access_token = None , session_type = None , loop = None ):
42+ def __init__ (self , http_provider , client_id = None , scopes = None , access_token = None , session_type = None , loop = None ,
43+ auth_server_url = None , auth_token_url = None ):
4344 """Initialize the authentication provider for authenticating
4445 requests sent to OneDrive
4546
@@ -63,13 +64,19 @@ def __init__(self, http_provider, client_id=None, scopes=None, access_token=None
6364 loop to use for all async requests. If none is provided,
6465 asyncio.get_event_loop() will be called. If using Python
6566 3.3 or below this does not need to be specified
67+ auth_server_url (str): URL where OAuth authentication can be performed. If
68+ None, defaults to OAuth for Microsoft Account.
69+ auth_token_url (str): URL where OAuth token can be redeemed. If None,
70+ defaults to OAuth for Microsoft Account.
6671 """
6772 self ._http_provider = http_provider
6873 self ._client_id = client_id
6974 self ._scopes = scopes
7075 self ._access_token = access_token
7176 self ._session_type = Session if session_type is None else session_type
7277 self ._session = None
78+ self ._auth_server_url = self .AUTH_SERVER_URL if auth_server_url is None else auth_server_url
79+ self ._auth_token_url = self .AUTH_TOKEN_URL if auth_token_url is None else auth_token_url
7380
7481 if sys .version_info >= (3 , 4 , 0 ):
7582 import asyncio
@@ -117,6 +124,34 @@ def access_token(self):
117124 def access_token (self , value ):
118125 self ._access_token = value
119126
127+ @property
128+ def auth_server_url (self ):
129+ """Gets and sets the authorization server url for the
130+ AuthProvider
131+
132+ Returns:
133+ str: Auth server url
134+ """
135+ return self ._auth_server_url
136+
137+ @auth_server_url .setter
138+ def auth_server_url (self , value ):
139+ self ._auth_server_url = value
140+
141+ @property
142+ def auth_token_url (self ):
143+ """Gets and sets the authorization token url for the
144+ AuthProvider
145+
146+ Returns:
147+ str: The auth token url
148+ """
149+ return self ._auth_token_url
150+
151+ @auth_token_url .setter
152+ def auth_token_url (self , value ):
153+ self ._auth_token_url = value
154+
120155 def get_auth_url (self , redirect_uri ):
121156 """Build the auth url using the params provided
122157 and the auth_provider
@@ -132,7 +167,7 @@ def get_auth_url(self, redirect_uri):
132167 "response_type" : "code" ,
133168 "redirect_uri" : redirect_uri
134169 }
135- return "{}?{}" .format (self .AUTH_SERVER_URL , urlencode (params ))
170+ return "{}?{}" .format (self ._auth_server_url , urlencode (params ))
136171
137172 def authenticate (self , code , redirect_uri , client_secret = None , resource = None ):
138173 """Takes in a code string, gets the access token,
@@ -165,7 +200,7 @@ def authenticate(self, code, redirect_uri, client_secret=None, resource=None):
165200 headers = {"Content-Type" : "application/x-www-form-urlencoded" }
166201 response = self ._http_provider .send (method = "POST" ,
167202 headers = headers ,
168- url = self .AUTH_TOKEN_URL ,
203+ url = self ._auth_token_url ,
169204 data = params )
170205
171206 rcont = json .loads (response .content )
@@ -174,7 +209,7 @@ def authenticate(self, code, redirect_uri, client_secret=None, resource=None):
174209 rcont ["scope" ],
175210 rcont ["access_token" ],
176211 self .client_id ,
177- self .AUTH_TOKEN_URL ,
212+ self ._auth_token_url ,
178213 redirect_uri ,
179214 rcont ["refresh_token" ] if "refresh_token" in rcont else None ,
180215 client_secret )
0 commit comments