Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changing package to work with react-native-fetch-blob #15

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions lib/Auth.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
import uuid from 'uuid';
import querystring from 'query-string';
import RNFetchBlob from 'react-native-fetch-blob';
import URL from 'url';
import {
Buffer
} from 'buffer';

const { Blob } = RNFetchBlob.polyfill;
const { fs } = RNFetchBlob;
window.XMLHttpRequest = RNFetchBlob.polyfill.XMLHttpRequest;
window.Blob = Blob;
window.fetch = new RNFetchBlob.polyfill.Fetch({
// enable this option so that the response data conversion handled automatically
auto: true,
// when receiving response data, the module will match its Content-Type header
// with strings in this array. If it contains any one of string in this array,
// the response body will be considered as binary data and the data will be stored
// in file system instead of in memory.
// By default, it only store response data to file system when Content-Type
// contains string `application/octet`.
binaryContentTypes: ['image/', 'video/', 'audio/', 'foo/'],
}).build();

export default class Auth {

constructor(instance) {
Expand Down Expand Up @@ -79,8 +96,8 @@ export default class Auth {
}, options);

// request token
return fetch(endpoint, payload)
.then(response => {
return RNFetchBlob.fetch(payload.method, endpoint, { 'Content-Type': 'application/x-www-form-urlencoded'}, payload.body)
.then(response => {
// return blob object
return response.json()
})
Expand Down
4 changes: 2 additions & 2 deletions lib/AzureInstance.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
export default class AzureInstance {
constructor(credentials) {
this.authority = 'https://login.microsoftonline.com/common';
this.authority = `https://login.microsoftonline.com/${credentials.tenant || 'common'}`;
this.authorize_endpoint = '/oauth2/v2.0/authorize';
this.redirect_uri = credentials.redirect_uri || 'https://localhost:3000/login';
this.redirect_uri = credentials.redirect_uri;
this.token_endpoint ='/oauth2/v2.0/token';
this.client_id = credentials.client_id;
this.client_secret = credentials.client_secret;
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"dependencies": {
"buffer": "^5.0.0",
"query-string": "^4.2.3",
"react-native-fetch-blob": "^0.10.8",
"url": "^0.11.0",
"uuid": "^2.0.3"
},
Expand Down