Skip to content

Window is not defined #307

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

Closed
Akxe opened this issue Jul 30, 2020 · 8 comments
Closed

Window is not defined #307

Akxe opened this issue Jul 30, 2020 · 8 comments
Assignees
Labels
ADO to GitHub automation label Issue caused by core project dependency modules or library enhancement
Milestone

Comments

@Akxe
Copy link

Akxe commented Jul 30, 2020

Bug Report
Prerequisites

Can you reproduce the problem?
Are you running the latest version?
Are you reporting to the correct repository?
Did you perform a cursory search?

For more information, see the CONTRIBUTING guide.
Description
Error when following steps in the readme.
Console Errors:
C:\Users\akxe\Documents\Programming\rita\node_modules\msal\src\cache\BrowserStorage.ts:18
if (!window) {
^
ReferenceError: window is not defined
at AuthCache.BrowserStorage (C:\Users\akxe\Documents\Programming\rita\node_modules\msal\src\cache\BrowserStorage.ts:18:9)
at new AuthCache (C:\Users\akxe\Documents\Programming\rita\node_modules\msal\src\cache\AuthCache.ts:22:9)
at new UserAgentApplication (C:\Users\akxe\Documents\Programming\rita\node_modules\msal\src\UserAgentApplication.ts:230:29)
at Module../apps/server/src/mail-adapter/microsoft/provider.ts (C:\Users\akxe\Documents\Programming\rita\dist\apps\server\webpack:\apps\server\src\mail-adapter\microsoft\provider.ts:17:2)
at webpack_require (C:\Users\akxe\Documents\Programming\rita\dist\apps\server\webpack:\webpack\bootstrap:19:1)
at Module../apps/server/src/main.ts (C:\Users\akxe\Documents\Programming\rita\dist\apps\server\main.js:518:90)
at webpack_require (C:\Users\akxe\Documents\Programming\rita\dist\apps\server\webpack:\webpack\bootstrap:19:1)
at Object.0 (C:\Users\akxe\Documents\Programming\rita\dist\apps\server\main.js:1133:18)
at webpack_require (C:\Users\akxe\Documents\Programming\rita\dist\apps\server\webpack:\webpack\bootstrap:19:1)
at C:\Users\akxe\Documents\Programming\rita\dist\apps\server\webpack:\webpack\bootstrap:83:1

Screenshots: Not needed
Steps to Reproduce
Create in NodeJS environment:
const authProvider = new ImplicitMSALAuthenticationProvider(
new UserAgentApplication( {
auth: {
clientId: process.env.MICROSOFT_ID!, // Client Id of the registered application
redirectUri: process.env.MICROSOFT_SECRET!,
},
}),
new MSALAuthenticationProviderOptions(process.env.MICROSOFT_SCOPES!.split(' ')),
);

const client = Client.initWithMiddleware({ authProvider });
Expected behavior: No error when following readme
Actual behavior: Error...

Maybe use globalThis to check?
Additional Context
I am transpiling from TS to JS.
Usage Information
SDK Version - [SDK version you are using]

Node (Check, if using Node version of SDK)

Node Version - v14.4.0

Browser (Check, if using Browser version of SDK)

Browser Name - ---

Version - ---
AB#5598

@ghost ghost added the ToTriage label Jul 30, 2020
@ddyett
Copy link
Contributor

ddyett commented Aug 3, 2020

the flow here works for browser but does not work for node since msal does not currently support the credential flows needed for client. For node you'd need to handle the authentication portion. see this PR for how someone recently implemented auth on node.

https://github.com/Huachao/vscode-restclient/pull/649/files#diff-24da39a94536877488c5fa835c5212dd

//cc @nikithauc

@Akxe
Copy link
Author

Akxe commented Aug 3, 2020

@ddyett Is there no plan to have even some in-memory token cache? I have enough work for now not to worry about it, but in two weeks I will have to and I hope there will be some simpler solution that implementing some half inner parts of Azure auth...

I think that many would appreciate an easy way to plug and play for the nodeJS environment too, even if it would not be "production-ready"

@ddyett
Copy link
Contributor

ddyett commented Aug 3, 2020

we are investigating some support here. I'll see if we can use azure identity as an answer here.

@ghost ghost removed the ToTriage label Aug 3, 2020
@Akxe
Copy link
Author

Akxe commented Aug 3, 2020

@ddyett I am not even sure what Azure identity is :D

I only want a nodeJS to be able to read and send mail on behalf of any of the users in our organization. (No client-side only server)

@ddyett ddyett added the ADO to GitHub automation label Issue caused by core project dependency modules or library label Aug 4, 2020
@ddyett ddyett assigned nikithauc and unassigned nikithauc Aug 4, 2020
@nikithauc nikithauc added this to the 3.0.0 milestone Dec 5, 2020
@nikithauc
Copy link
Contributor

This features should be available after adding @azure/identity token credential support.

@Akxe
Copy link
Author

Akxe commented Dec 5, 2020

@nikithauc Is there any example to follow?

@nikithauc
Copy link
Contributor

@Akxe Currently the work is in progress to add token credential support in the SDK.

Please see if the following links help -
https://www.npmjs.com/package/@azure/identity

Register your application to enable authentication to Azure Active Directory using the client secret credential. For more details, please check the following links

Register an application

documention.

You could try implement your own custom authentication provider with uses the TokenCredential - https://github.com/microsoftgraph/msgraph-sdk-javascript/blob/dev/docs/CustomAuthenticationProvider.md. and return the access token in the getAccessToken() method of your custom Auth Provider.

@nikithauc
Copy link
Contributor

Duplicate to #237

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ADO to GitHub automation label Issue caused by core project dependency modules or library enhancement
Projects
None yet
Development

No branches or pull requests

3 participants