- 
                Notifications
    You must be signed in to change notification settings 
- Fork 334
Microsoft 365 OAuth #14135
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
          
     Merged
      
      
    
  
     Merged
                    Microsoft 365 OAuth #14135
Changes from all commits
      Commits
    
    
            Show all changes
          
          
            49 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      7925951
              
                tester
              
              
                GregoryTravis c63801f
              
                wip
              
              
                GregoryTravis 1ef8e0e
              
                import style, open lib
              
              
                GregoryTravis eb911d0
              
                initial open
              
              
                GregoryTravis 5fb6e5e
              
                get auth code
              
              
                GregoryTravis ddc2e2d
              
                return auth code, ignore favicon
              
              
                GregoryTravis 25595da
              
                post, but failing for no grant_type
              
              
                GregoryTravis 514f64f
              
                try axios
              
              
                GregoryTravis 5b5692c
              
                got at
              
              
                GregoryTravis 5646c0d
              
                async
              
              
                GregoryTravis 5f61fa9
              
                ac+at combined function
              
              
                GregoryTravis 8a20fa0
              
                separate ac and at
              
              
                GregoryTravis f8e8396
              
                successful call to /me
              
              
                GregoryTravis 64205d8
              
                wip
              
              
                GregoryTravis 2cf0f74
              
                id keys
              
              
                GregoryTravis 8307b77
              
                id vars
              
              
                GregoryTravis 08be34e
              
                works
              
              
                GregoryTravis 7ba2b7f
              
                Merge branch 'develop' into wip/gmt/12929-ms-oauth
              
              
                GregoryTravis 6dde986
              
                wip
              
              
                GregoryTravis 3368612
              
                wip
              
              
                GregoryTravis e6d79e7
              
                build, dev-env client ids
              
              
                GregoryTravis bef9563
              
                Merge branch 'develop' into wip/gmt/12929-ms-oauth
              
              
                GregoryTravis 0828b7c
              
                Merge branch 'develop' into wip/gmt/12929-ms-oauth
              
              
                GregoryTravis 228e32c
              
                extra scopes
              
              
                GregoryTravis 79a2749
              
                remove oauth
              
              
                GregoryTravis 6618e70
              
                revert
              
              
                GregoryTravis e7f43f0
              
                changelog
              
              
                GregoryTravis 815d5b6
              
                Merge branch 'develop' into wip/gmt/12929-ms-oauth
              
              
                GregoryTravis 0fc7163
              
                update dev-env
              
              
                GregoryTravis be3b6b9
              
                update dev-env
              
              
                GregoryTravis 266742c
              
                update dev-env
              
              
                GregoryTravis 7b72e3b
              
                update dev-env
              
              
                GregoryTravis afe312e
              
                Merge branch 'develop' into wip/gmt/12929-ms-oauth
              
              
                GregoryTravis 32a24df
              
                update dev-env
              
              
                GregoryTravis 880c948
              
                decode_as_json
              
              
                GregoryTravis 561ce79
              
                just rename enso lib instances
              
              
                GregoryTravis ba4c742
              
                wip
              
              
                GregoryTravis 4fada58
              
                dropdown name
              
              
                GregoryTravis 9b03222
              
                revert bazel lock
              
              
                GregoryTravis 6e80534
              
                doc methods
              
              
                GregoryTravis 055e524
              
                api
              
              
                GregoryTravis 3966dcd
              
                prettier
              
              
                GregoryTravis 7ce7665
              
                Merge branch 'develop' into wip/gmt/12929-ms-oauth
              
              
                GregoryTravis a9bee23
              
                update dev-env
              
              
                GregoryTravis db87c39
              
                no comma between scopes
              
              
                GregoryTravis 6928e51
              
                Merge branch 'develop' into wip/gmt/12929-ms-oauth
              
              
                GregoryTravis 0c4a827
              
                fix merge
              
              
                GregoryTravis af7e237
              
                merge
              
              
                GregoryTravis 49c526f
              
                Merge branch 'develop' into wip/gmt/12929-ms-oauth
              
              
                GregoryTravis File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
          Some comments aren't visible on the classic Files Changed page.
        
There are no files selected for viewing
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
  
    
      
          
            50 changes: 50 additions & 0 deletions
          
          50 
        
  app/gui/src/dashboard/data/serviceCredentials/MS365CredentialsForm.tsx
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| /** | ||
| * @file | ||
| * Dialog for an MS365 credential. | ||
| * Remember to ensure this component is added to `CREDENTIAL_INFOS` in `constants.ts`. | ||
| */ | ||
|  | ||
| import { Checkbox } from '#/components/Checkbox' | ||
| import { Form } from '#/components/Form' | ||
| import { Input } from '#/components/Inputs/Input' | ||
| import { useToastAndLog } from '#/hooks/toastAndLogHooks' | ||
| import { useText } from '$/providers/react' | ||
| import { CredentialsFormFooter } from './CredentialsFormFooter' | ||
| import * as ms365 from './ms365' | ||
| import type { CredentialFormProps } from './types' | ||
|  | ||
| /** Dialog for a MS365 credential. */ | ||
| export function MS365CredentialsForm(props: CredentialFormProps) { | ||
| const { createCredentials } = props | ||
| const { getText } = useText() | ||
| const toastAndLog = useToastAndLog() | ||
|  | ||
| return ( | ||
| <Form | ||
| method="dialog" | ||
| schema={ms365.FORM_SCHEMA} | ||
| defaultValues={{ | ||
| scopes: ['User.Read', 'Files.Read'], | ||
| }} | ||
| className="w-full" | ||
| onSubmit={async (values) => { | ||
| try { | ||
| await ms365.submitForm(createCredentials, values) | ||
| } catch (error) { | ||
| toastAndLog(null, error) | ||
| } | ||
| }} | ||
| > | ||
| {(form) => ( | ||
| <> | ||
| <Input form={form} name="name" label={getText('name')} /> | ||
| <Checkbox.Group form={form} name="scopes" label={getText('ms365CredentialScopes')}> | ||
| <Checkbox value="User.Read">{getText('ms365CredentialUserReadScope')}</Checkbox> | ||
| <Checkbox value="Files.Read">{getText('ms365CredentialFilesReadScope')}</Checkbox> | ||
| </Checkbox.Group> | ||
| <CredentialsFormFooter isCreating={true} canCancel={false} canReset={false} /> | ||
| </> | ||
| )} | ||
| </Form> | ||
| ) | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,55 @@ | ||
| /** | ||
| * @file Definitions for the MS365 credentials integration. | ||
| */ | ||
| import invariant from 'tiny-invariant' | ||
|  | ||
| import type { MS365CredentialInput, SecretId } from '#/services/Backend' | ||
| import * as i18n from 'enso-common/src/text' | ||
| import { z } from 'zod' | ||
| import type { CredentialRecipe } from './types' | ||
| import { getOauthRedirectUri } from './utilities' | ||
|  | ||
| const EXTRA_SCOPES = ['openid', 'profile', 'offline_access'] | ||
|  | ||
| export const FORM_SCHEMA = z.object({ | ||
| name: z.string().min(1), | ||
| scopes: z.array(z.string()).refine((scopes) => scopes.length > 0, { | ||
| message: i18n.getText(i18n.resolveDictionary(), 'ms365CredentialScopesEmptyError'), | ||
| }), | ||
| }) | ||
|  | ||
| /** | ||
| * The logic for submitting the MS365 credential form. | ||
| */ | ||
| export function submitForm( | ||
| createCredentials: (recipe: CredentialRecipe) => Promise<void>, | ||
| values: z.infer<typeof FORM_SCHEMA>, | ||
| ): Promise<void> { | ||
| invariant($config.MS365_OAUTH_CLIENT_ID != null, 'MS365 OAuth client id is missing') | ||
| const ms365OauthClientId = $config.MS365_OAUTH_CLIENT_ID | ||
|  | ||
| const oauthScopes: string[] = [...EXTRA_SCOPES, ...values.scopes] | ||
| const input: MS365CredentialInput = { | ||
| type: 'MS365', | ||
| scopes: oauthScopes, | ||
| } | ||
| return createCredentials({ | ||
| name: values.name, | ||
| input, | ||
| makeAuthUrl: (secretId: SecretId, nonce: string) => { | ||
| const state = btoa(JSON.stringify({ secretId, nonce })) | ||
| const scope = oauthScopes.join(' ') | ||
| const query = new URLSearchParams({ | ||
| /* eslint-disable @typescript-eslint/naming-convention, camelcase */ | ||
| client_id: ms365OauthClientId, | ||
| redirect_uri: getOauthRedirectUri('MS365'), | ||
| response_type: 'code', | ||
| response_mode: 'query', | ||
| state, | ||
| scope, | ||
| /* eslint-enable @typescript-eslint/naming-convention, camelcase */ | ||
| }) | ||
| return `https://login.microsoftonline.com/common/oauth2/v2.0/authorize?${query.toString()}` | ||
| }, | ||
| }) | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
  
    
      
          
            7 changes: 7 additions & 0 deletions
          
          7 
        
  distribution/lib/Standard/Microsoft/0.0.0-dev/docs/api/Microsoft365.md
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ## Enso Signatures 1.0 | ||
| ## module Standard.Microsoft.Microsoft365 | ||
| - type Microsoft365 | ||
| - initialize credentials:Standard.Base.Any.Any -> Standard.Base.Any.Any | ||
| - list_root self -> Standard.Base.Any.Any | ||
| - to_js_object self -> Standard.Base.Any.Any | ||
| - user self -> Standard.Base.Any.Any | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
  
    
      
          
            52 changes: 52 additions & 0 deletions
          
          52 
        
  distribution/lib/Standard/Microsoft/0.0.0-dev/src/Microsoft365.enso
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| from Standard.Base import all | ||
| from Standard.Base.Enso_Cloud.Enso_Secret import as_credential_reference | ||
|  | ||
| polyglot java import org.enso.base.enso_cloud.ExternalLibraryCredentialHelper.CredentialReference | ||
| polyglot java import org.enso.microsoft.ms365.MS365Service | ||
|  | ||
| type Microsoft365 | ||
| ## --- | ||
| private: true | ||
| --- | ||
| private Service (ms365_service:MS365Service) | ||
|  | ||
| ## --- | ||
| icon: cloud | ||
| --- | ||
| Initializes the Microsoft365 instance using the given credentials file. | ||
|  | ||
| ## Arguments: | ||
| - `credentials`: a Cloud secret or a file containing Microsoft365 credentials. | ||
| initialize : File|Enso_Secret -> Microsoft365 | ||
| initialize credentials = | ||
| credentials_reference = as_credential_reference credentials | ||
| Microsoft365.Service (MS365Service.new credentials_reference) | ||
|  | ||
| ## --- | ||
| icon: cloud | ||
| --- | ||
|  | ||
| Fetches the profile of the current user. | ||
| user self = | ||
| _ms365_get self (_base_url + "/me") | ||
|  | ||
| ## --- | ||
| icon: cloud | ||
| --- | ||
|  | ||
| Lists the root directory of the user's OneDrive. | ||
| list_root self = | ||
| _ms365_get self (_base_url + "/me/drive/root/children") | ||
|  | ||
| ## --- | ||
| private: true | ||
| --- | ||
| to_js_object : JS_Object | ||
| to_js_object self = | ||
| JS_Object.from_pairs [["type", "MS365"]] | ||
|  | ||
| private _base_url = 'https://graph.microsoft.com/v1.0' | ||
|  | ||
| private _ms365_get ms365 url = | ||
| header = Header.authorization_bearer ms365.ms365_service.getAccessToken.token | ||
| HTTP.fetch url headers=[header] . decode_as_json | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.