Login with Microsoft authentication

174 views
Skip to first unread message

Václav Petrák

unread,
Jun 19, 2023, 11:17:03 AM6/19/23
to Google Apps Script Community
Hello,
I'm asking the community for help.
Is it possible to create an application via HTMLservice.
The application should be accessible to anonymous users.
But in the application there would be a button "Login with Microsoft authentication"
When clicked, the user would go through the login on the Microsoft side.
The HTMLservice application would receive the result of the login.
Is it possible to do this via GAS?

Thank you very much and sorry for my bad English.

Václav Petrák

💼

unread,
Jun 19, 2023, 12:35:48 PM6/19/23
to google-apps-sc...@googlegroups.com
What “result” should it receive from the login page? You can embed the login widget using iframe but to pass any info from it to the parent you need to control (edit) that resource. 

On Jun 19, 2023, at 5:17 PM, Václav Petrák <waclav...@gmail.com> wrote:

Hello,
--
You received this message because you are subscribed to the Google Groups "Google Apps Script Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to google-apps-script-c...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-apps-script-community/4e8406b9-d958-4902-ad3a-2910157fde1an%40googlegroups.com.

Václav Petrák

unread,
Jun 20, 2023, 2:50:22 AM6/20/23
to Google Apps Script Community
I would like to get only the email - which the user enters at login and the result of the authentication.  

I need to solve in HTML service what is described here:

I am making an application for an organization where all employees have Microsoft accounts. So I don't want to maintain a database with emails and passwords for this application. I just want the user's email and confirmation that it is really him.

Thanks



Dne pondělí 19. června 2023 v 18:35:48 UTC+2 uživatel webd...@gmail.com napsal:

Emerson Maia

unread,
Jun 20, 2023, 4:58:00 AM6/20/23
to google-apps-sc...@googlegroups.com
good morning, can you try something like this,

// Import the OAuth2 library
const OAuth2 = OAuth2.createService('microsoft')
  .setClientId('{YOUR_CLIENT_ID}')
  .setClientSecret('{YOUR_CLIENT_SECRET}')
  .setCallbackFunction('authCallback')
  .setPropertyStore(PropertiesService.getUserProperties());

// Function to initiate the authorization flow
function startAuth() {
  const authorizationUrl = OAuth2.getAuthorizationUrl();
  console.log('Authorization URL:', authorizationUrl);
}

// Callback function to receive the access token
function authCallback(request) {
  const isAuthorized = OAuth2.handleCallback(request);
  if (isAuthorized) {
    console.log('Authorized successfully!');
  } else {
    console.log('Authorization failed.');
  }
}

// Example usage
function exampleUsage() {
  if (!OAuth2.hasAccess()) {
    const authorizationUrl = OAuth2.getAuthorizationUrl();
    console.log('Authorization URL:', authorizationUrl);
  } else {
    // Here you can make authenticated API calls to Microsoft
    // using the access token
    const accessToken = OAuth2.getAccessToken();
    console.log('Access Token:', accessToken);
    
    // Make API calls with the access token
    // ...
  }
}


--

Emerson Maia

unread,
Jun 20, 2023, 5:26:47 AM6/20/23
to google-apps-sc...@googlegroups.com
forgot to comment, use clasp +parcel

Em seg., 19 de jun. de 2023 às 12:17, Václav Petrák <waclav...@gmail.com> escreveu:
--

Hashcrypt Hash

unread,
Aug 8, 2024, 7:41:22 AM8/8/24
to Google Apps Script Community
// Import the OAuth2 library

const OAuth2 = OAuth2.createService('facebook')
  .setAuthorizationBaseUrl('https://www.facebook.com/dialog/oauth')
  .setClientId('****')
  .setClientSecret('****')

when I'm running above code I'm getting below error

ReferenceError: Cannot access 'OAuth2' before initialization

Reply all
Reply to author
Forward
0 new messages