public RefreshTokenAuthenticationProvider(string clientId, string clientSecret, string redirectUri, OAuthSession session, Action <string> storeSession) { this.Session = session; this.ClientID = clientId; this.ClientSecret = ClientSecret; this.RedirectUri = redirectUri; this.storeSession = storeSession; }
public OneDriveClient(string clientId, string clientSecret, string redirectUri, OAuthSession session, Action <string> storeSession) { this.Session = session; this.ClientID = clientId; this.ClientSecret = clientSecret; this.RedirectUri = redirectUri; this.storeSession = storeSession; }
public async Task AuthenticateRequestAsync(HttpRequestMessage request) { if (!Session.IsValid()) { Session = await AuthenticationHelper.RequestAccessToken(ClientID, ClientSecret, RedirectUri, Session.RefreshToken); storeSession?.Invoke(JsonConvert.SerializeObject(Session)); } request.Headers.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", Session.AccessToken); }
public async Task <bool> Authenticate(Dictionary <string, string> data) { OAuthSession session = await AuthenticationHelper.RequestRefreshToken(ClientID, ClientSecret, callbackUrl, data["code"]); if (session == null || !session.IsValid()) { throw new ArgumentNullException("Failed to retreive refresh_token"); } storeSession?.Invoke(JsonConvert.SerializeObject(session)); return(true); }
public OneDriveClient GetAuthenticatedClient(string storedSession) { OAuthSession session = JsonConvert.DeserializeObject <OAuthSession>(storedSession); if (string.IsNullOrWhiteSpace(session.RefreshToken)) { throw new ArgumentNullException(nameof(session.RefreshToken)); } OneDriveClient client = new OneDriveClient(ClientID, ClientSecret, callbackUrl, session, this.storeSession); return(client); }
public IOneDriveClient GetAuthenticatedClient(string storedSession) { OAuthSession session = JsonConvert.DeserializeObject <OAuthSession>(storedSession); if (string.IsNullOrWhiteSpace(session.RefreshToken)) { throw new ArgumentNullException(nameof(session.RefreshToken)); } RefreshTokenAuthenticationProvider authenticationProvider = new RefreshTokenAuthenticationProvider(ClientID, ClientSecret, callbackUrl, session, this.storeSession); IOneDriveClient client = new OneDriveClient("https://api.onedrive.com/v1.0", authenticationProvider); return(client); }