浏览代码
Branch with Beta packages included.
Branch with Beta packages included.
Meant to be a "It Just works" branch for internal use./main
当前提交
ebccd32c
共有 865 个文件被更改,包括 3797 次插入 和 90 次删除
-
22Packages/manifest.json
-
55Packages/packages-lock.json
-
24ProjectSettings/PackageManagerSettings.asset
-
6ProjectSettings/ProjectSettings.asset
-
41README.md
-
242Packages/com.unity.services.authentication/.README - External.md
-
53Packages/com.unity.services.authentication/CHANGELOG.md
-
7Packages/com.unity.services.authentication/CHANGELOG.md.meta
-
5Packages/com.unity.services.authentication/Documentation~/com.unity.services.authentication.md
-
8Packages/com.unity.services.authentication/Editor.meta
-
5Packages/com.unity.services.authentication/Editor/AssemblyInfo.cs
-
3Packages/com.unity.services.authentication/Editor/AssemblyInfo.cs.meta
-
298Packages/com.unity.services.authentication/Editor/AuthenticationAdminClient.cs
-
3Packages/com.unity.services.authentication/Editor/AuthenticationAdminClient.cs.meta
-
148Packages/com.unity.services.authentication/Editor/AuthenticationAdminNetworkClient.cs
-
11Packages/com.unity.services.authentication/Editor/AuthenticationAdminNetworkClient.cs.meta
-
17Packages/com.unity.services.authentication/Editor/AuthenticationIdentifier.cs
-
11Packages/com.unity.services.authentication/Editor/AuthenticationIdentifier.cs.meta
-
47Packages/com.unity.services.authentication/Editor/AuthenticationService.cs
-
11Packages/com.unity.services.authentication/Editor/AuthenticationService.cs.meta
-
292Packages/com.unity.services.authentication/Editor/AuthenticationSettingsElement.cs
-
3Packages/com.unity.services.authentication/Editor/AuthenticationSettingsElement.cs.meta
-
47Packages/com.unity.services.authentication/Editor/AuthenticationSettingsHelper.cs
-
3Packages/com.unity.services.authentication/Editor/AuthenticationSettingsHelper.cs.meta
-
58Packages/com.unity.services.authentication/Editor/AuthenticationSettingsProvider.cs
-
11Packages/com.unity.services.authentication/Editor/AuthenticationSettingsProvider.cs.meta
-
20Packages/com.unity.services.authentication/Editor/AuthenticationTopMenu.cs
-
11Packages/com.unity.services.authentication/Editor/AuthenticationTopMenu.cs.meta
-
79Packages/com.unity.services.authentication/Editor/IAuthenticationAdminClient.cs
-
3Packages/com.unity.services.authentication/Editor/IAuthenticationAdminClient.cs.meta
-
399Packages/com.unity.services.authentication/Editor/IdProviderElement.cs
-
3Packages/com.unity.services.authentication/Editor/IdProviderElement.cs.meta
-
8Packages/com.unity.services.authentication/Editor/Models.meta
-
49Packages/com.unity.services.authentication/Editor/Models/CreateIdProviderRequest.cs
-
11Packages/com.unity.services.authentication/Editor/Models/CreateIdProviderRequest.cs.meta
-
20Packages/com.unity.services.authentication/Editor/Models/DeleteIdProviderRequest.cs
-
11Packages/com.unity.services.authentication/Editor/Models/DeleteIdProviderRequest.cs.meta
-
19Packages/com.unity.services.authentication/Editor/Models/GetIdDomainResponse.cs
-
11Packages/com.unity.services.authentication/Editor/Models/GetIdDomainResponse.cs.meta
-
56Packages/com.unity.services.authentication/Editor/Models/IdProviderResponse.cs
-
11Packages/com.unity.services.authentication/Editor/Models/IdProviderResponse.cs.meta
-
19Packages/com.unity.services.authentication/Editor/Models/ListIdProviderResponse.cs
-
11Packages/com.unity.services.authentication/Editor/Models/ListIdProviderResponse.cs.meta
-
29Packages/com.unity.services.authentication/Editor/Models/TokenExchangeErrorResponse.cs
-
11Packages/com.unity.services.authentication/Editor/Models/TokenExchangeErrorResponse.cs.meta
-
16Packages/com.unity.services.authentication/Editor/Models/TokenExchangeRequest.cs
-
11Packages/com.unity.services.authentication/Editor/Models/TokenExchangeRequest.cs.meta
-
16Packages/com.unity.services.authentication/Editor/Models/TokenExchangeResponse.cs
-
11Packages/com.unity.services.authentication/Editor/Models/TokenExchangeResponse.cs.meta
-
44Packages/com.unity.services.authentication/Editor/Models/UpdateIdProviderRequest.cs
-
11Packages/com.unity.services.authentication/Editor/Models/UpdateIdProviderRequest.cs.meta
-
3Packages/com.unity.services.authentication/Editor/USS.meta
-
41Packages/com.unity.services.authentication/Editor/USS/AuthenticationStyleSheet.uss
-
3Packages/com.unity.services.authentication/Editor/USS/AuthenticationStyleSheet.uss.meta
-
3Packages/com.unity.services.authentication/Editor/UXML.meta
-
15Packages/com.unity.services.authentication/Editor/UXML/AuthenticationProjectSettings.uxml
-
3Packages/com.unity.services.authentication/Editor/UXML/AuthenticationProjectSettings.uxml.meta
-
12Packages/com.unity.services.authentication/Editor/UXML/IdProviderElement.uxml
-
3Packages/com.unity.services.authentication/Editor/UXML/IdProviderElement.uxml.meta
-
10Packages/com.unity.services.authentication/Editor/Unity.Services.Authentication.Editor.api
-
7Packages/com.unity.services.authentication/Editor/Unity.Services.Authentication.Editor.api.meta
-
23Packages/com.unity.services.authentication/Editor/Unity.Services.Authentication.Editor.asmdef
-
7Packages/com.unity.services.authentication/Editor/Unity.Services.Authentication.Editor.asmdef.meta
-
5Packages/com.unity.services.authentication/LICENSE.md
-
7Packages/com.unity.services.authentication/LICENSE.md.meta
-
79Packages/com.unity.services.authentication/README.md
-
7Packages/com.unity.services.authentication/README.md.meta
-
8Packages/com.unity.services.authentication/Runtime.meta
-
127Packages/com.unity.services.authentication/Runtime/AuthenticationAsyncOperation.cs
-
3Packages/com.unity.services.authentication/Runtime/AuthenticationAsyncOperation.cs.meta
-
58Packages/com.unity.services.authentication/Runtime/AuthenticationError.cs
-
3Packages/com.unity.services.authentication/Runtime/AuthenticationError.cs.meta
-
49Packages/com.unity.services.authentication/Runtime/AuthenticationException.cs
-
3Packages/com.unity.services.authentication/Runtime/AuthenticationException.cs.meta
-
209Packages/com.unity.services.authentication/Runtime/AuthenticationNetworkClient.cs
-
11Packages/com.unity.services.authentication/Runtime/AuthenticationNetworkClient.cs.meta
-
12Packages/com.unity.services.authentication/Runtime/AuthenticationService.cs
-
11Packages/com.unity.services.authentication/Runtime/AuthenticationService.cs.meta
-
645Packages/com.unity.services.authentication/Runtime/AuthenticationServiceInternal.cs
-
11Packages/com.unity.services.authentication/Runtime/AuthenticationServiceInternal.cs.meta
-
48Packages/com.unity.services.authentication/Runtime/CodeChallengeGenerator.cs
-
11Packages/com.unity.services.authentication/Runtime/CodeChallengeGenerator.cs.meta
-
8Packages/com.unity.services.authentication/Runtime/Core.meta
-
16Packages/com.unity.services.authentication/Runtime/Core/AccessTokenComponent.cs
-
3Packages/com.unity.services.authentication/Runtime/Core/AccessTokenComponent.cs.meta
-
51Packages/com.unity.services.authentication/Runtime/Core/AuthenticationPackageInitializer.cs
-
11Packages/com.unity.services.authentication/Runtime/Core/AuthenticationPackageInitializer.cs.meta
-
40Packages/com.unity.services.authentication/Runtime/Core/PlayerIdComponent.cs
|
|||
# UPM Package Starter Kit |
|||
|
|||
The purpose of this starter kit is to provide the data structure and development guidelines for new packages meant for the **Unity Package Manager (UPM)**. |
|||
|
|||
## Are you ready to become a package? |
|||
The Package Manager is a work-in-progress for Unity and, in that sense, there are a few criteria that must be met for your package to be considered on the package list at this time: |
|||
- **Your code accesses public Unity C# APIs only.** If you have a native code component, it will need to ship with an official editor release. Internal API access might eventually be possible for Unity made packages, but not at this time. |
|||
- **Your code doesn't require security, obfuscation, or conditional access control.** Anyone should be able to download your package and access the source code. |
|||
|
|||
|
|||
## Package structure |
|||
|
|||
```none |
|||
<root> |
|||
├── package.json |
|||
├── README.md |
|||
├── CHANGELOG.md |
|||
├── LICENSE.md |
|||
├── Third Party Notices.md |
|||
├── QAReport.md |
|||
├── Editor |
|||
│ ├── Unity.[YourPackageName].Editor.asmdef |
|||
│ └── EditorExample.cs |
|||
├── Runtime |
|||
│ ├── Unity.[YourPackageName].asmdef |
|||
│ └── RuntimeExample.cs |
|||
├── Tests |
|||
│ ├── .tests.json |
|||
│ ├── Editor |
|||
│ │ ├── Unity.[YourPackageName].Editor.Tests.asmdef |
|||
│ │ └── EditorExampleTest.cs |
|||
│ └── Runtime |
|||
│ ├── Unity.[YourPackageName].Tests.asmdef |
|||
│ └── RuntimeExampleTest.cs |
|||
├── Samples |
|||
│ └── Example |
|||
│ ├── .sample.json |
|||
│ └── SampleExample.cs |
|||
└── Documentation~ |
|||
├── your-package-name.md |
|||
└── Images |
|||
``` |
|||
|
|||
## Develop your package |
|||
Package development works best within the Unity Editor. Here's how to set that up: |
|||
|
|||
1. Start **Unity**, create a local empty project. |
|||
|
|||
1. In a console (or terminal) application, go to the newly created project folder, then copy the contents of this starter kit into the packages directory. |
|||
__Note:__ Your directory name must be the name of your package (Example: `"com.unity.terrain-builder"`) |
|||
|
|||
1. ##### Fill in your package information |
|||
|
|||
Update the following required fields in file **package.json**: |
|||
- `"name"`: Package name, it should follow this naming convention: `"com.[YourCompanyName].[sub-group].[your-package-name]"` |
|||
(Example: `"com.unity.2d.animation"`, where `sub-group` should match the sub-group you selected in Gitlab) |
|||
- `"displayName"`: Package user friendly display name. (Example: `"Terrain Builder SDK"`). <br>__Note:__ Use a display name that will help users understand what your package is intended for. |
|||
- `"version"`: Package version `"X.Y.Z"`, your project **must** adhere to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). |
|||
Follow this guideline: |
|||
- To introduce a new feature or bug fix, increment the minor version (X.**Y**.Z) |
|||
- To introduce a breaking API change, increment the major version (**X**.Y.Z) |
|||
- The patch version (X.Y.**Z**), is reserved for sustainable engineering use only. |
|||
- `"unity"`: Unity Version your package is compatible with. (Example: `"2018.1"`) |
|||
- `"description"`: This description appears in the Package Manager window when the user selects this package from the list. For best results, use this text to summarize what the package does and how it can benefit the user.<br>__Note:__ Special formatting characters are supported, including line breaks (`\n`) and unicode characters such as bullets (`\u25AA`).<br> |
|||
|
|||
Update the following recommended fields in file **package.json**: |
|||
- `"dependencies"`: List of packages this package depends on. All dependencies will also be downloaded and loaded in a project with your package. Here's an example: |
|||
``` |
|||
dependencies: { |
|||
"com.unity.ads": "1.0.0" |
|||
"com.unity.analytics": "2.0.0" |
|||
} |
|||
``` |
|||
- `"keywords"`: List of words that will be indexed by the package manager search engine to facilitate discovery. |
|||
|
|||
Update the following field in file **Tests/.tests.json**: |
|||
- `"createSeparatePackage"`: If this is set to true, the CI will create a separate package for these tests. If you leave it set to false, the tests will remain part of the published package. If you set it to true, the tests in your package will automatically be moved to a separate package, and metadata will be added at publish time to link the packages together. This allows you to have a large number of tests, or assets, etc. that you don't want to include in your main package, while making it easy to test your package with those tests & fixtures. |
|||
|
|||
1. You should now see your package in the Project Window, along with all other available packages for your project. |
|||
|
|||
1. ##### Rename and update assembly definition files. |
|||
|
|||
Assembly definition files are used to generate C# assemblies during compilation. Package code must include asmdef files to ensure package code isolation. You can read up on assembly definition files [here](https://docs.unity3d.com/Manual/ScriptCompilationAssemblyDefinitionFiles.html). |
|||
|
|||
If your package contains Editor code, rename and modify [Editor/Unity.YourPackageName.Editor.asmdef](Editor/Unity.YourPackageName.Editor.asmdef). Otherwise, delete the Editor directory. |
|||
* Name **must** match your package name, suffixed by `.Editor` (i.e `Unity.[YourPackageName].Editor`) |
|||
* Assembly **must** reference `Unity.[YourPackageName]` (if you have any Runtime) |
|||
* Platforms **must** include `"Editor"` |
|||
|
|||
If your package contains code that needs to be included in Unity runtime builds, rename and modify [Runtime/Unity.YourPackageName.asmdef](Runtime/Unity.YourPackageName.asmdef). Otherwise, delete the Runtime directory. |
|||
* Name **must** match your package name (i.e `Unity.[YourPackageName]`) |
|||
|
|||
If your package has Editor code, you **must** include Editor Tests in your package. In that case, rename and modify [Tests/Editor/Unity.YourPackageName.Editor.Tests.asmdef](Tests/Editor/Unity.YourPackageName.Editor.Tests.asmdef). |
|||
* Name **must** match your package name, suffixed by `.Editor.Tests` (i.e `Unity.[YourPackageName].Editor.Tests`) |
|||
* Assembly **must** reference `Unity.[YourPackageName].Editor` and `Unity.[YourPackageName]` (if you have any Runtime) |
|||
* Platforms **must** include `"Editor"` |
|||
* Optional Unity references **must** include `"TestAssemblies"` to allow your Editor Tests to show up in the Test Runner/run on Katana when your package is listed in project manifest `testables` |
|||
|
|||
If your package has Runtime code, you **must** include Playmode Tests in your package. In that case, rename and modify [Tests/Runtime/Unity.YourPackageName.Tests.asmdef](Tests/Runtime/Unity.YourPackageName.Tests.asmdef). |
|||
* Name **must** match your package name, suffixed by `.Tests` (i.e `Unity.[YourPackageName].Tests`) |
|||
* Assembly **must** reference `Unity.[YourPackageName]` |
|||
* Optional Unity references **must** include `"TestAssemblies"` to allow your Playmode Tests to show up in the Test Runner/run on Katana when your package is listed in project manifest `testables` |
|||
|
|||
> |
|||
> The reason for choosing such name schema is to ensure that the name of the assembly built based on *assembly definition file* (_a.k.a .asmdef_) will follow the .Net [Framework Design Guidelines](https://docs.microsoft.com/en-us/dotnet/standard/design-guidelines/index) |
|||
|
|||
1. ##### Document your package. |
|||
|
|||
Rename and update **your-package-name.md** documentation file. Use this documentation template file to create preliminary, high-level documentation. This document is meant to introduce users to the features and sample files included in your package. Your package documentation files will be used to generate online and local docs, available from the package manager UI. |
|||
|
|||
**Document your public APIs** |
|||
* All public APIs need to be documented with XmlDoc. If you don't need an API to be accessed by clients, mark it as internal instead. |
|||
* API documentation is generated from [XmlDoc tags](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/xmldoc/xml-documentation-comments) included with all public APIs found in the package. See [Editor/EditorExample.cs](Editor/EditorExample.cs) for an example. |
|||
|
|||
**Documentation flow** |
|||
* Documentation needs to be ready when a publish request is sent to Release Management, as they will ask the documentation team to review it. |
|||
* The package will remain in `preview` mode until the final documentation is completed. Users will have access to the developer-generated documentation only in preview packages. |
|||
* When the documentation is completed, the documentation team will update the package git repo with the updates and they will publish it on the web. |
|||
* The package's development team will then need to submit a new package version with updated docs. |
|||
* The starting page in the user manual that links to package documentation is [Here](https://docs.unity3d.com/Manual/PackagesList.html). |
|||
* The `Documentation~` folder is suffixed with `~` so that its content does not get loaded in the editor, which is the recommended behavior. If this is problematic, you can still name it `Documentation` and all tools will still work correctly. `.Documentation` is also supported. |
|||
|
|||
**Test your documentation locally** |
|||
As you are developing your documentation, you can see what your documentation will look like by using the DocTools extension (optional). |
|||
Once the DocTools package is installed, it will add a `Generate Documentation` button in the Package Manager UI's details of your installed packages. To install the extension, follow these steps: |
|||
|
|||
1. Make sure you have `Package Manager UI v1.9.6` or above. |
|||
1. Your project manifest will need to point to a staging registry for this, which you can do by adding this line to it: `"registry": "https://staging-packages.unity.com"` |
|||
1. Install `Package Manager DocTools v1.0.0-preview.6` or above from the `Package Manager UI` (in the `All Packages` section). |
|||
1. After installation, you will see a `Generate Documentation` button which will generate the documentation locally, and open a web browser to a locally served version of your documentation so you can preview it. |
|||
1. (optional) If your package documentation contains multiple `.md` files for the user manual, see [this page](https://docs.unity3d.com/Packages/com.unity.package-manager-doctools@1.0/manual/index.html#table-of-content) to add a table of content to your documentation. |
|||
|
|||
The DocTools extension is still in preview, if you come across arguable results, please discuss them on #docs-packman. |
|||
|
|||
1. ##### Add samples to your package (code & assets). |
|||
If your package contains a sample, rename the `Samples/Example` folder, and update the `.sample.json` file in it. |
|||
|
|||
In the case where your package contains multiple samples, you can make a copy of the `Samples/Example` folder for each sample, and update the `.sample.json` file accordingly. |
|||
|
|||
Similar to `.tests.json` file, there is a `"createSeparatePackage"` field in `.sample.json`.If set to true, the CI will create an separate package for the sample.. |
|||
|
|||
Delete the `Samples` folder altogether if your package does not need samples. |
|||
|
|||
As of Unity release 2019.1, the /Samples directory of a package will be recognized by the package manager. Samples will not be imported to Unity when the package is added to a project, but will instead be offered to users of the package as an optional import, which can be added to their "/Assets" directory through a UI option. |
|||
|
|||
1. ##### Validate your package. |
|||
|
|||
Before you publish your package, you need to make sure that it passes all the necessary validation checks by using the Package Validation Suite extension (optional). |
|||
Once the Validation Suite package is installed, it will add a `Validate` button in the Package Manager UI's details of your installed packages. To install the extension, follow these steps: |
|||
|
|||
1. Make sure you have `Package Manager UI v1.9.6` or above. |
|||
1. Your project manifest will need to point to a staging registry for this, which you can do by adding this line to it: `"registry": "https://staging-packages.unity.com"` |
|||
1. Install `Package Validation Suite v0.3.0-preview.13` or above from the `Package Manager UI` in the `All Packages` section. If you can't find it there, try turning on `Show preview packages` in the `Advanced` menu. |
|||
1. After installation, you will see a `Validate` button show up in the Package Manager UI, which, when pressed, will run a series of tests and expose a `See Results` button for additional explanation. |
|||
1. If it succeeds, you will see a green bar with a `Success` message. |
|||
1. If it fails, you will see a red bar with a `Failed` message. |
|||
|
|||
The validation suite is still in preview, if you come across arguable results, please discuss them on #release-management. |
|||
|
|||
1. ##### Add tests to your package. |
|||
|
|||
All packages must contain tests. Tests are essential for Unity to ensure that the package works as expected in different scenarios. |
|||
|
|||
**Editor tests** |
|||
* Write all your Editor Tests in `Tests/Editor` |
|||
|
|||
**Playmode Tests** |
|||
* Write all your Playmode Tests in `Tests/Runtime`. |
|||
|
|||
1. ##### Update **CHANGELOG.md**. |
|||
|
|||
Every new feature or bug fix should have a trace in this file. For more details on the chosen changelog format, see [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). |
|||
|
|||
## Create a Pre-Release Package |
|||
Pre-Release Packages are a great way of getting your features in front of Unity Developers in order to get early feedback on functionality and UI designs. Pre-Release packages need to go through the publishing to production flow, as would any other package, but with diminished requirements. Here are the supported Pre-Release tags (to be used in package.json,`version` field), along with the requirements for each one: |
|||
|
|||
**Preview** - ex: `"version" : "1.2.0-preview"` |
|||
* Expected Package structure respected |
|||
* Package loads in Unity Editor without errors |
|||
* License file present - With third party notices file if necessary |
|||
* Test coverage is good - Optional but preferred |
|||
* Public APIs documented, minimal feature docs exists- Optional but preferred |
|||
|
|||
## Make sure your package meets all legal requirements |
|||
|
|||
##### Update **Third Party Notices.md** & **License.md** |
|||
|
|||
1. If your package has third-party elements and its licenses are approved, then all the licenses must be added to the `Third Party Notices.md` file. Simply duplicate the `Component Name/License Type/Provide License Details` section if you have more then one licenes. |
|||
|
|||
a. Concerning `[Provide License Details]` in the `Third Party Notices.md`, a URL can work as long as it actually points to the reproduced license and the copyright information _(if applicable)_. |
|||
|
|||
1. If your package does not have third party elements, you can remove the `Third Party Notices.md` file from your package. |
|||
|
|||
## Preparing your package for Staging |
|||
|
|||
Before publishing your package to production, you must send your package on the Package Manager's **staging** repository. The staging repository is monitored by QA and release management, and is where package validation will take place before it is accepted in production. |
|||
## *** IMPORTANT: The staging repository is publicly accessible, do not publish any packages with sensitive material you aren't ready to share with the public *** |
|||
|
|||
|
|||
1. Publishing your changes to the package manager's **staging** repository happens from Gitlab. To do so, simply setup your project's Continuous integration, which will be triggered by "Tags" on your branches. |
|||
* Join the **#devs-packman** channel on Slack, and request a staging **USERNAME** and **API_KEY**. |
|||
* In Gitlab, under the **Settings-> CI/CD -> Secret Variables** section, setup the following 2 project variables: |
|||
* API_KEY = [your API KEY] |
|||
* USER_NAME = [your USER NAME@unity] |
|||
* You're almost done! To publish a version of your package, make sure all your changes are checked into Gitlab, then create a new tag to reflect the version you are publishing (ex. "v1.2.2"), **the tag will trigger a publish to Staging**. You can view progress you the publish request by switch over to the "CI / CD" part of your project. |
|||
|
|||
1. Do it yourself CI |
|||
|
|||
If you are using your own CI, it is still recommended that you use the `build.sh` wrapper script that comes with the starter kit, as it handle the installation of the actual CI build scripts for you. |
|||
|
|||
Instead of calling `npm pack` and `npm publish` in the package root folder in your CI, use |
|||
``` |
|||
./build.sh package-ci pack --git-head $CI_COMMIT_SHA --git-url $CI_REPOSITORY_URL |
|||
``` |
|||
and |
|||
``` |
|||
./build.sh package-ci publish --git-head $CI_COMMIT_SHA --git-url $CI_REPOSITORY_URL |
|||
``` |
|||
respectively. |
|||
|
|||
1. Test your package locally |
|||
|
|||
Now that your package is published on the package manager's **staging** repository, you can test your package in the editor by creating a new project, and editing the project's `manifest.json` file to point to your staging package, as such: |
|||
``` |
|||
dependencies: { |
|||
"com.[YourCompanyName].[sub-group].[your-package-name]": "0.1.0" |
|||
}, |
|||
"registry": "https://staging-packages.unity.com" |
|||
``` |
|||
|
|||
## Get your package published to Production |
|||
|
|||
Packages are promoted to the **production** repository from **staging**, described above. |
|||
|
|||
Once you feel comfortable that your package is ready for prime time, and passes validation (Validation Suite), reach out to Unity so your package can be passed along to Release Management, for evaluation. |
|||
|
|||
**Release management will validate your package content, and check that the editor/playmode tests are passed before promoting the package to production. You will receive a confirmation email once the package is in production.** |
|||
|
|||
**You're almost done!** |
|||
At this point, your package is available on the cloud, but not discoverable through the editor: |
|||
|
|||
1. Contact the Package Manager team to ask them to add your package to the list of discoverable package for the Unity Editor. All you need to provide is the package name (com.[YourCompanyName].[sub-group].[your-package-name]) |
|
|||
# Changelog |
|||
All notable changes to this package will be documented in this file. |
|||
|
|||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) |
|||
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html). |
|||
|
|||
## [Unreleased] |
|||
|
|||
## [0.4.0-preview] - 2021-06-16 |
|||
### Changed |
|||
- Remove `SetOAuthClient()` as the authentication flow is simplified. |
|||
- Updated the initialization code to initialize with `UnityServices.Initialize()` |
|||
|
|||
## [0.4.0-preview] - 2021-06-07 |
|||
### Added |
|||
- Added Project Settings UI to configure ID providers. |
|||
- Added `SignInWithSteam`, `LinkWithSteam` functions. |
|||
- Changed the public interface of the Authentication service from a static instance and static methods to a singleton instance hidden behind an interface. |
|||
|
|||
### Changed |
|||
- Change the public signature of `Authentication` to return a Task, as opposed to a IAsyncOperation |
|||
- Change the public API names of `Authentication` to `Async` |
|||
|
|||
## [0.3.1-preview] - 2021-04-23 |
|||
### Changed |
|||
- Change the `SignInFailed` event to take `AuthenticationException` instead of a string as parameter. It can provide more information for debugging purposes. |
|||
- Fixed the `com.unity.services.core` package dependency version. |
|||
|
|||
## [0.3.0-preview] - 2021-04-21 |
|||
### Added |
|||
- Added `SignInWithApple`, `LinkWithApple`, `SignInWithGoogle`, `LinkWithGoogle`, `SignInWithFacebook`, `LinkWithFacebook` functions. |
|||
- Added `SignInWithSessionToken` |
|||
- Added error codes used by the social scenarios to `AuthenticationError`. |
|||
|
|||
## [0.2.3-preview] - 2021-03-23 |
|||
### Changed |
|||
- Rename the package from `com.unity.services.identity` to `com.unity.services.authentication`. Renamed the internal types/methods, too. |
|||
|
|||
## [0.2.2-preview] - 2021-03-15 |
|||
### Added |
|||
- Core package integration |
|||
|
|||
## [0.2.1-preview] - 2021-03-05 |
|||
|
|||
- Fixed dependency on Utilities package |
|||
|
|||
## [0.2.0-preview] - 2021-03-05 |
|||
|
|||
- Removed requirement for OAuth client ID to be specified (automatically uses project default OAuth client) |
|||
|
|||
## [0.1.0-preview] - 2021-01-18 |
|||
|
|||
### This is the first release of *com.unity.services.identity*. |
|
|||
fileFormatVersion: 2 |
|||
guid: 06e5cc5b0f38f824b835fc371283773e |
|||
TextScriptImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
# About Authentication SDK |
|||
|
|||
This is the Authentication SDK, a way to manage player accounts through the Unity User Authentication Service (UAS). |
|||
|
|||
This package is currently in pre-release state and is not guaranteed to be fully functional. |
|
|||
fileFormatVersion: 2 |
|||
guid: 9ab04733f4c8a4d7181b07dfa234aa46 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Runtime.CompilerServices; |
|||
|
|||
[assembly: InternalsVisibleTo("Unity.Services.Authentication.EditorTests")] |
|||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] // For Moq
|
|
|||
fileFormatVersion: 2 |
|||
guid: 80f9842e95c141e59bcc9d49c93cc2e1 |
|||
timeCreated: 1620833560 |
|
|||
using System; |
|||
using System.Reflection; |
|||
using System.Runtime.CompilerServices; |
|||
using Newtonsoft.Json; |
|||
using Unity.Services.Authentication.Editor.Models; |
|||
using Unity.Services.Authentication.Models; |
|||
using Unity.Services.Authentication.Utilities; |
|||
using Unity.Services.Core; |
|||
using UnityEditor; |
|||
using UnityEngine; |
|||
using ILogger = Unity.Services.Authentication.Utilities.ILogger; |
|||
using Logger = Unity.Services.Authentication.Utilities.Logger; |
|||
|
|||
[assembly: InternalsVisibleTo("Unity.Services.Authentication.Editor.Tests")] |
|||
[assembly: InternalsVisibleTo("Unity.Services.Authentication.EditorTests")] |
|||
[assembly: InternalsVisibleTo("DynamicProxyGenAssembly2")] // For Moq
|
|||
|
|||
namespace Unity.Services.Authentication.Editor |
|||
{ |
|||
static class AuthenticationAdminClientManager |
|||
{ |
|||
internal static IAuthenticationAdminClient Instance { get; set; } = AuthenticationAdminClient(); |
|||
|
|||
static IAuthenticationAdminClient AuthenticationAdminClient() |
|||
{ |
|||
var logger = new Logger("[Authentication]"); |
|||
IDateTimeWrapper dateTime = new DateTimeWrapper(); |
|||
INetworkingUtilities networkUtilities = new NetworkingUtilities(null, logger); |
|||
string orgId = GetOrganizationId(); |
|||
var networkClient = new AuthenticationAdminNetworkClient("https://services.unity.com", |
|||
orgId, |
|||
CloudProjectSettings.projectId, |
|||
networkUtilities, |
|||
logger); |
|||
|
|||
return new AuthenticationAdminClient(logger, networkClient); |
|||
} |
|||
|
|||
// GetOrganizationId will gets the organization id associated with this Unity project.
|
|||
static string GetOrganizationId() |
|||
{ |
|||
// This is a temporary workaround to get the Genesis organization foreign key for non-DevX enhanced Unity versions.
|
|||
// When the eventual changes are backported into previous versions of Unity, this will no longer be necessary.
|
|||
Assembly assembly = Assembly.GetAssembly(typeof(EditorWindow)); |
|||
var unityConnectInstance = assembly.CreateInstance("UnityEditor.Connect.UnityConnect", false, BindingFlags.NonPublic | BindingFlags.Instance, null, null, null, null); Type t = unityConnectInstance.GetType(); |
|||
var projectInfo = t.GetProperty("projectInfo").GetValue(unityConnectInstance, null); |
|||
|
|||
Type projectInfoType = projectInfo.GetType(); |
|||
return projectInfoType.GetProperty("organizationForeignKey").GetValue(projectInfo, null) as string; |
|||
} |
|||
} |
|||
|
|||
class AuthenticationAdminClient : IAuthenticationAdminClient |
|||
{ |
|||
string m_IdDomain; |
|||
IAuthenticationAdminNetworkClient m_AuthenticationAdminNetworkClient; |
|||
ILogger m_Logger; |
|||
|
|||
string m_orgForeignKey; |
|||
string m_servicesGatewayToken; |
|||
string m_genesisToken; |
|||
|
|||
internal enum ServiceCalled |
|||
{ |
|||
TokenExchange, |
|||
AuthenticationAdmin |
|||
} |
|||
|
|||
public AuthenticationAdminClient(ILogger logger, IAuthenticationAdminNetworkClient networkClient, string genesisToken = "") |
|||
{ |
|||
m_Logger = logger; |
|||
m_AuthenticationAdminNetworkClient = networkClient; |
|||
m_genesisToken = genesisToken; |
|||
} |
|||
|
|||
public IAsyncOperation<string> GetIDDomain() |
|||
{ |
|||
var asyncOp = new AsyncOperation<string>(); |
|||
Action<string> getIdDomainFunc = token => |
|||
{ |
|||
var getDefaultIdDomainRequest = m_AuthenticationAdminNetworkClient.GetDefaultIdDomain(token); |
|||
getDefaultIdDomainRequest.Completed += request => HandleGetIdDomainAPICall(asyncOp, request); |
|||
}; |
|||
|
|||
getGenesisToken(); |
|||
var tokenAsyncOp = ExchangeToken(m_genesisToken); |
|||
tokenAsyncOp.Completed += tokenAsyncOpResult => getIdDomainFunc(tokenAsyncOpResult?.Result); |
|||
return asyncOp; |
|||
} |
|||
|
|||
public IAsyncOperation<IdProviderResponse> CreateIdProvider(string iddomain, CreateIdProviderRequest body) |
|||
{ |
|||
var asyncOp = new AsyncOperation<IdProviderResponse>(); |
|||
Action<string> createIdProviderFunc = token => |
|||
{ |
|||
var request = m_AuthenticationAdminNetworkClient.CreateIdProvider(body, iddomain, token); |
|||
request.Completed += req => HandleIdProviderResponseApiCall(asyncOp, req); |
|||
}; |
|||
|
|||
getGenesisToken(); |
|||
var tokenAsyncOp = ExchangeToken(m_genesisToken); |
|||
tokenAsyncOp.Completed += tokenAsyncOpResult => createIdProviderFunc(tokenAsyncOpResult?.Result); |
|||
return asyncOp; |
|||
} |
|||
|
|||
public IAsyncOperation<ListIdProviderResponse> ListIdProviders(string iddomain) |
|||
{ |
|||
var asyncOp = new AsyncOperation<ListIdProviderResponse>(); |
|||
Action<string> listIdProviderFunc = token => |
|||
{ |
|||
var request = m_AuthenticationAdminNetworkClient.ListIdProvider(iddomain, token); |
|||
request.Completed += req => HandleListIdProviderResponseApiCall(asyncOp, req); |
|||
}; |
|||
|
|||
getGenesisToken(); |
|||
var tokenAsyncOp = ExchangeToken(m_genesisToken); |
|||
tokenAsyncOp.Completed += tokenAsyncOpResult => listIdProviderFunc(tokenAsyncOpResult?.Result); |
|||
return asyncOp; |
|||
} |
|||
|
|||
public IAsyncOperation<IdProviderResponse> UpdateIdProvider(string iddomain, string type, UpdateIdProviderRequest body) |
|||
{ |
|||
var asyncOp = new AsyncOperation<IdProviderResponse>(); |
|||
Action<string> enableIdProviderFunc = token => |
|||
{ |
|||
var request = m_AuthenticationAdminNetworkClient.UpdateIdProvider(body, iddomain, type, token); |
|||
request.Completed += req => HandleIdProviderResponseApiCall(asyncOp, req); |
|||
}; |
|||
|
|||
getGenesisToken(); |
|||
var tokenAsyncOp = ExchangeToken(m_genesisToken); |
|||
tokenAsyncOp.Completed += tokenAsyncOpResult => enableIdProviderFunc(tokenAsyncOpResult?.Result); |
|||
return asyncOp; |
|||
} |
|||
|
|||
public IAsyncOperation<IdProviderResponse> EnableIdProvider(string iddomain, string type) |
|||
{ |
|||
var asyncOp = new AsyncOperation<IdProviderResponse>(); |
|||
Action<string> enableIdProviderFunc = token => |
|||
{ |
|||
var request = m_AuthenticationAdminNetworkClient.EnableIdProvider(iddomain, type, token); |
|||
request.Completed += req => HandleIdProviderResponseApiCall(asyncOp, req); |
|||
}; |
|||
|
|||
getGenesisToken(); |
|||
var tokenAsyncOp = ExchangeToken(m_genesisToken); |
|||
tokenAsyncOp.Completed += tokenAsyncOpResult => enableIdProviderFunc(tokenAsyncOpResult?.Result); |
|||
return asyncOp; |
|||
} |
|||
|
|||
public IAsyncOperation<IdProviderResponse> DisableIdProvider(string iddomain, string type) |
|||
{ |
|||
var asyncOp = new AsyncOperation<IdProviderResponse>(); |
|||
Action<string> disableIdProviderFunc = token => |
|||
{ |
|||
var request = m_AuthenticationAdminNetworkClient.DisableIdProvider(iddomain, type, token); |
|||
request.Completed += req => HandleIdProviderResponseApiCall(asyncOp, req); |
|||
}; |
|||
|
|||
getGenesisToken(); |
|||
var tokenAsyncOp = ExchangeToken(m_genesisToken); |
|||
tokenAsyncOp.Completed += tokenAsyncOpResult => disableIdProviderFunc(tokenAsyncOpResult?.Result); |
|||
return asyncOp; |
|||
} |
|||
|
|||
public IAsyncOperation<IdProviderResponse> DeleteIdProvider(string iddomain, string type) |
|||
{ |
|||
var asyncOp = new AsyncOperation<IdProviderResponse>(); |
|||
Action<string> deleteIdProviderFunc = token => |
|||
{ |
|||
var request = m_AuthenticationAdminNetworkClient.DeleteIdProvider(iddomain, type, token); |
|||
request.Completed += req => HandleIdProviderResponseApiCall(asyncOp, req); |
|||
}; |
|||
|
|||
getGenesisToken(); |
|||
var tokenAsyncOp = ExchangeToken(m_genesisToken); |
|||
tokenAsyncOp.Completed += tokenAsyncOpResult => deleteIdProviderFunc(tokenAsyncOpResult?.Result); |
|||
return asyncOp; |
|||
} |
|||
|
|||
public IdProviderResponse CloneIdProvider(IdProviderResponse x) |
|||
{ |
|||
return x.Clone(); |
|||
} |
|||
|
|||
internal IAsyncOperation<string> ExchangeToken(string token) |
|||
{ |
|||
var asyncOp = new AsyncOperation<string>(); |
|||
var request = m_AuthenticationAdminNetworkClient.TokenExchange(token); |
|||
request.Completed += req => HandleTokenExchange(asyncOp, req); |
|||
return asyncOp; |
|||
} |
|||
|
|||
void HandleGetIdDomainAPICall(AsyncOperation<string> asyncOp, IWebRequest<GetIdDomainResponse> request) |
|||
{ |
|||
if (HandleError(asyncOp, request, ServiceCalled.AuthenticationAdmin)) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
m_IdDomain = request?.ResponseBody?.Id; |
|||
asyncOp.Succeed(request?.ResponseBody?.Id); |
|||
} |
|||
|
|||
void HandleTokenExchange(AsyncOperation<string> asyncOp, IWebRequest<TokenExchangeResponse> request) |
|||
{ |
|||
if (HandleError(asyncOp, request, ServiceCalled.TokenExchange)) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
var token = request?.ResponseBody?.Token; |
|||
m_servicesGatewayToken = token; |
|||
asyncOp.Succeed(token); |
|||
} |
|||
|
|||
void HandleIdProviderResponseApiCall(AsyncOperation<IdProviderResponse> asyncOp, IWebRequest<IdProviderResponse> request) |
|||
{ |
|||
if (HandleError(asyncOp, request, ServiceCalled.AuthenticationAdmin)) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
asyncOp.Succeed(request?.ResponseBody); |
|||
} |
|||
|
|||
void HandleListIdProviderResponseApiCall(AsyncOperation<ListIdProviderResponse> asyncOp, IWebRequest<ListIdProviderResponse> request) |
|||
{ |
|||
if (HandleError(asyncOp, request, ServiceCalled.AuthenticationAdmin)) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
asyncOp.Succeed(request?.ResponseBody); |
|||
} |
|||
|
|||
void HandleEmptyResponseApiCall(AsyncOperation<IdProviderResponse> asyncOp, IWebRequest<IdProviderResponse> request) |
|||
{ |
|||
if (HandleError(asyncOp, request, ServiceCalled.AuthenticationAdmin)) |
|||
{ |
|||
return; |
|||
} |
|||
|
|||
asyncOp.Succeed(request?.ResponseBody); |
|||
} |
|||
|
|||
internal bool HandleError<Q, T>(AsyncOperation<Q> asyncOp, IWebRequest<T> request, ServiceCalled sc) |
|||
{ |
|||
if (!request.RequestFailed) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
if (request.NetworkError) |
|||
{ |
|||
asyncOp.Fail(new AuthenticationException(AuthenticationError.NetworkError)); |
|||
return true; |
|||
} |
|||
m_Logger?.Error("Error message: " + request.ErrorMessage); |
|||
|
|||
try |
|||
{ |
|||
switch (sc) |
|||
{ |
|||
case ServiceCalled.TokenExchange: |
|||
var tokenExchangeErrorResponse = JsonConvert.DeserializeObject<TokenExchangeErrorResponse>(request.ErrorMessage); |
|||
asyncOp.Fail(new AuthenticationException(tokenExchangeErrorResponse.Name, tokenExchangeErrorResponse.Message)); |
|||
break; |
|||
case ServiceCalled.AuthenticationAdmin: |
|||
var authenticationAdminErrorResponse = JsonConvert.DeserializeObject<AuthenticationErrorResponse>(request.ErrorMessage); |
|||
asyncOp.Fail(new AuthenticationException(authenticationAdminErrorResponse.Title, authenticationAdminErrorResponse.Detail)); |
|||
break; |
|||
default: |
|||
asyncOp.Fail(new AuthenticationException(AuthenticationError.UnknownError, "Unknown error")); |
|||
break; |
|||
} |
|||
} |
|||
catch (JsonException ex) |
|||
{ |
|||
asyncOp.Fail(new AuthenticationException(AuthenticationError.UnknownError, "Failed to deserialize server response: " + request.ErrorMessage)); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
asyncOp.Fail(new AuthenticationException(AuthenticationError.UnknownError, "Unknown error deserializing server response: " + request.ErrorMessage)); |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
|
|||
void getGenesisToken() |
|||
{ |
|||
if (m_genesisToken == "") |
|||
{ |
|||
m_genesisToken = CloudProjectSettings.accessToken; |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: ca4a5cace103447794de02de329b8eeb |
|||
timeCreated: 1620234241 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.Services.Authentication.Editor.Models; |
|||
using Unity.Services.Authentication.Utilities; |
|||
using UnityEngine; |
|||
using ILogger = Unity.Services.Authentication.Utilities.ILogger; |
|||
|
|||
namespace Unity.Services.Authentication.Editor |
|||
{ |
|||
interface IAuthenticationAdminNetworkClient |
|||
{ |
|||
IWebRequest<TokenExchangeResponse> TokenExchange(string token); |
|||
IWebRequest<GetIdDomainResponse> GetDefaultIdDomain(string token); |
|||
IWebRequest<IdProviderResponse> CreateIdProvider(CreateIdProviderRequest body, string idDomain, string token); |
|||
IWebRequest<ListIdProviderResponse> ListIdProvider(string idDomain, string token); |
|||
IWebRequest<IdProviderResponse> UpdateIdProvider(UpdateIdProviderRequest body, string idDomain, string type, string token); |
|||
IWebRequest<IdProviderResponse> EnableIdProvider(string idDomain, string type, string token); |
|||
IWebRequest<IdProviderResponse> DisableIdProvider(string idDomain, string type, string token); |
|||
IWebRequest<IdProviderResponse> DeleteIdProvider(string idDomain, string type, string token); |
|||
} |
|||
|
|||
class AuthenticationAdminNetworkClient : IAuthenticationAdminNetworkClient |
|||
{ |
|||
const string k_ServicesGatewayStem = "/api/player-identity/v1/organizations/"; |
|||
const string k_GetDefaultIdDomainStem = "/iddomains/default"; |
|||
const string k_TokenExchangeStem = "/api/auth/v1/genesis-token-exchange/unity"; |
|||
|
|||
readonly string m_ServicesGatewayHost; |
|||
|
|||
readonly string m_GetDefaultIdDomainUrl; |
|||
readonly string m_TokenExchangeUrl; |
|||
|
|||
readonly string m_OrganizationId; |
|||
readonly string m_ProjectId; |
|||
|
|||
readonly INetworkingUtilities m_NetworkClient; |
|||
|
|||
readonly Dictionary<string, string> m_CommonPlayerIdentityHeaders; |
|||
|
|||
internal AuthenticationAdminNetworkClient(string servicesGatewayHost, |
|||
string organizationId, |
|||
string projectId, |
|||
INetworkingUtilities networkClient, |
|||
ILogger logger) |
|||
{ |
|||
m_ServicesGatewayHost = servicesGatewayHost; |
|||
m_OrganizationId = organizationId; |
|||
m_ProjectId = projectId; |
|||
|
|||
m_GetDefaultIdDomainUrl = servicesGatewayHost + k_ServicesGatewayStem + organizationId + k_GetDefaultIdDomainStem; |
|||
m_TokenExchangeUrl = servicesGatewayHost + k_TokenExchangeStem; |
|||
m_NetworkClient = networkClient; |
|||
|
|||
m_CommonPlayerIdentityHeaders = new Dictionary<string, string> |
|||
{ |
|||
["ProjectId"] = projectId, |
|||
// The Error-Version header enables RFC7807HttpError error responses
|
|||
["Error-Version"] = "v1" |
|||
}; |
|||
} |
|||
|
|||
public IWebRequest<GetIdDomainResponse> GetDefaultIdDomain(string token) |
|||
{ |
|||
return m_NetworkClient.Get<GetIdDomainResponse>(m_GetDefaultIdDomainUrl, addTokenHeader(m_CommonPlayerIdentityHeaders, token)); |
|||
} |
|||
|
|||
public IWebRequest<TokenExchangeResponse> TokenExchange(string token) |
|||
{ |
|||
var body = new TokenExchangeRequest(); |
|||
body.Token = token; |
|||
return m_NetworkClient.PostJson<TokenExchangeResponse>(m_TokenExchangeUrl, body); |
|||
} |
|||
|
|||
public IWebRequest<IdProviderResponse> CreateIdProvider(CreateIdProviderRequest body, string idDomain, string token) |
|||
{ |
|||
return m_NetworkClient.PostJson<IdProviderResponse>(CreateIdProviderUrl(idDomain), body, addTokenHeader(m_CommonPlayerIdentityHeaders, token)); |
|||
} |
|||
|
|||
public IWebRequest<ListIdProviderResponse> ListIdProvider(string idDomain, string token) |
|||
{ |
|||
return m_NetworkClient.Get<ListIdProviderResponse>(ListIdProviderUrl(idDomain), addTokenHeader(m_CommonPlayerIdentityHeaders, token)); |
|||
} |
|||
|
|||
public IWebRequest<IdProviderResponse> UpdateIdProvider(UpdateIdProviderRequest body, string idDomain, string type, string token) |
|||
{ |
|||
return m_NetworkClient.Put<IdProviderResponse>(UpdateIdProviderUrl(idDomain, type), body, addTokenHeader(m_CommonPlayerIdentityHeaders, token)); |
|||
} |
|||
|
|||
public IWebRequest<IdProviderResponse> EnableIdProvider(string idDomain, string type, string token) |
|||
{ |
|||
return m_NetworkClient.Post<IdProviderResponse>(EnableIdProviderUrl(idDomain, type), addJsonHeader(addTokenHeader(m_CommonPlayerIdentityHeaders, token))); |
|||
} |
|||
|
|||
public IWebRequest<IdProviderResponse> DisableIdProvider(string idDomain, string type, string token) |
|||
{ |
|||
return m_NetworkClient.Post<IdProviderResponse>(DisableIdProviderUrl(idDomain, type), addJsonHeader(addTokenHeader(m_CommonPlayerIdentityHeaders, token))); |
|||
} |
|||
|
|||
public IWebRequest<IdProviderResponse> DeleteIdProvider(string idDomain, string type, string token) |
|||
{ |
|||
return m_NetworkClient.Delete<IdProviderResponse>(DeleteIdProviderUrl(idDomain, type), addTokenHeader(m_CommonPlayerIdentityHeaders, token)); |
|||
} |
|||
|
|||
Dictionary<string, string> addTokenHeader(Dictionary<string, string> d, string token) |
|||
{ |
|||
var headers = new Dictionary<string, string>(d); |
|||
headers.Add("Authorization", "Bearer " + token); |
|||
return headers; |
|||
} |
|||
|
|||
Dictionary<string, string> addJsonHeader(Dictionary<string, string> d) |
|||
{ |
|||
var headers = new Dictionary<string, string>(d); |
|||
headers.Add("Content-Type", "application/json"); |
|||
return headers; |
|||
} |
|||
|
|||
string CreateIdProviderUrl(string idDomain) |
|||
{ |
|||
return m_ServicesGatewayHost + k_ServicesGatewayStem + m_OrganizationId + "/iddomains/" + idDomain + "/idps"; |
|||
} |
|||
|
|||
string ListIdProviderUrl(string idDomain) |
|||
{ |
|||
return m_ServicesGatewayHost + k_ServicesGatewayStem + m_OrganizationId + "/iddomains/" + idDomain + "/idps"; |
|||
} |
|||
|
|||
string UpdateIdProviderUrl(string idDomain, string type) |
|||
{ |
|||
return m_ServicesGatewayHost + k_ServicesGatewayStem + m_OrganizationId + "/iddomains/" + idDomain + "/idps/" + type; |
|||
} |
|||
|
|||
string DeleteIdProviderUrl(string idDomain, string type) |
|||
{ |
|||
return m_ServicesGatewayHost + k_ServicesGatewayStem + m_OrganizationId + "/iddomains/" + idDomain + "/idps/" + type; |
|||
} |
|||
|
|||
string EnableIdProviderUrl(string idDomain, string type) |
|||
{ |
|||
return m_ServicesGatewayHost + k_ServicesGatewayStem + m_OrganizationId + "/iddomains/" + idDomain + "/idps/" + type + "/enable"; |
|||
} |
|||
|
|||
string DisableIdProviderUrl(string idDomain, string type) |
|||
{ |
|||
return m_ServicesGatewayHost + k_ServicesGatewayStem + m_OrganizationId + "/iddomains/" + idDomain + "/idps/" + type + "/disable"; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 45791e692f25c4a61adf3f50dc1397ac |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using Unity.Services.Core.Editor; |
|||
|
|||
namespace Unity.Services.Authentication.Editor |
|||
{ |
|||
/// <summary>
|
|||
/// Implementation of the <see cref="IEditorGameServiceIdentifier"/> for the Authentication package
|
|||
/// </summary>
|
|||
/// <remarks>This identifier MUST be public struct.</remarks>
|
|||
public struct AuthenticationIdentifier : IEditorGameServiceIdentifier |
|||
{ |
|||
/// <summary>
|
|||
/// Key for the Authentication package
|
|||
/// </summary>
|
|||
public string GetKey() => "Authentication"; |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 6ac6e0d63f116404caeed7d030ba58cb |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using Unity.Services.Core.Editor; |
|||
|
|||
namespace Unity.Services.Authentication.Editor |
|||
{ |
|||
class AuthenticationService : IEditorGameService |
|||
{ |
|||
/// <summary>
|
|||
/// Name of the service
|
|||
/// Used for error handling and service fetching
|
|||
/// </summary>
|
|||
public string Name => "Authentication Service"; |
|||
|
|||
/// <summary>
|
|||
/// Identifier for the service
|
|||
/// Used when registering and fetching the service
|
|||
/// </summary>
|
|||
public IEditorGameServiceIdentifier Identifier { get; } = new AuthenticationIdentifier(); |
|||
|
|||
/// <summary>
|
|||
/// Flag used to determine whether COPPA Compliance should be adhered to
|
|||
/// for this service
|
|||
/// </summary>
|
|||
public bool RequiresCoppaCompliance => false; |
|||
|
|||
/// <summary>
|
|||
/// Flag used to determine whether this service has a dashboard
|
|||
/// </summary>
|
|||
public bool HasDashboard => false; |
|||
|
|||
/// <summary>
|
|||
/// Getter for the formatted dashboard url
|
|||
/// If <see cref="HasDashboard"/> is false, this field only need return null or empty string
|
|||
/// </summary>
|
|||
/// <returns>The formatted URL</returns>
|
|||
public string GetFormattedDashboardUrl() |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// The enabler which allows the service to toggle on/off
|
|||
/// Can be set to null, in which case there would be no toggle
|
|||
/// </summary>
|
|||
public IEditorGameServiceEnabler Enabler { get; } = null; |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8907e4a6f69d84349b9fdf60013bdd52 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.Services.Authentication.Editor.Models; |
|||
using Unity.Services.Core; |
|||
using UnityEditor; |
|||
using UnityEditor.UIElements; |
|||
using UnityEngine; |
|||
using UnityEngine.UIElements; |
|||
|
|||
namespace Unity.Services.Authentication.Editor |
|||
{ |
|||
class AuthenticationSettingsElement : VisualElement |
|||
{ |
|||
const string k_Uxml = "Packages/com.unity.services.authentication/Editor/UXML/AuthenticationProjectSettings.uxml"; |
|||
const string k_Uss = "Packages/com.unity.services.authentication/Editor/USS/AuthenticationStyleSheet.uss"; |
|||
|
|||
IAuthenticationAdminClient m_AdminClient; |
|||
|
|||
string m_ProjectId; |
|||
string m_IdDomainId; |
|||
|
|||
// Whether skip the confirmation window for tests/automation.
|
|||
bool m_SkipConfirmation; |
|||
|
|||
TextElement m_WaitingTextElement; |
|||
TextElement m_ErrorTextElement; |
|||
VisualElement m_AddIdProviderContainer; |
|||
List<string> m_AddIdProviderTypeChoices; |
|||
PopupField<string> m_AddIdProviderType; |
|||
Button m_RefreshButton; |
|||
Button m_AddButton; |
|||
VisualElement m_IdProviderListContainer; |
|||
|
|||
/// <summary>
|
|||
/// The text to show when the settings is waitng for an async operation to finish.
|
|||
/// </summary>
|
|||
public TextElement WaitingTextElement => m_WaitingTextElement; |
|||
|
|||
/// <summary>
|
|||
/// The text to show when there is an error.
|
|||
/// </summary>
|
|||
public TextElement ErrorTextElement => m_ErrorTextElement; |
|||
|
|||
/// <summary>
|
|||
/// The add ID provider choices in the dropdown list.
|
|||
/// </summary>
|
|||
public IEnumerable<string> AddIdProviderTypeChoices => m_AddIdProviderTypeChoices; |
|||
|
|||
/// <summary>
|
|||
/// The add ID provider dropdown list.
|
|||
/// </summary>
|
|||
public PopupField<string> AddIdProviderType => m_AddIdProviderType; |
|||
|
|||
/// <summary>
|
|||
/// The button to refresh the ID provider list.
|
|||
/// </summary>
|
|||
public Button RefreshButton => m_RefreshButton; |
|||
|
|||
/// <summary>
|
|||
/// The button to add a new ID provider.
|
|||
/// </summary>
|
|||
public Button AddButton => m_AddButton; |
|||
|
|||
/// <summary>
|
|||
/// The container to add ID providers.
|
|||
/// </summary>
|
|||
public VisualElement IdProviderListContainer => m_IdProviderListContainer; |
|||
|
|||
/// <summary>
|
|||
/// Event triggered when the <cref="AuthenticationSettingsElement"/> starts or finishes waiting for an async operation.
|
|||
/// The first parameter of the callback is the sender.
|
|||
/// The second parameter is true if it starts waiting, and false if it finishes waiting.
|
|||
/// </summary>
|
|||
public event Action<AuthenticationSettingsElement, bool> Waiting; |
|||
|
|||
public AuthenticationSettingsElement(IAuthenticationAdminClient adminClient, string projectId, bool skipConfirmation = false) |
|||
{ |
|||
m_AdminClient = adminClient; |
|||
m_ProjectId = projectId; |
|||
m_SkipConfirmation = skipConfirmation; |
|||
|
|||
var containerAsset = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(k_Uxml); |
|||
if (containerAsset != null) |
|||
{ |
|||
var containerUI = containerAsset.CloneTree().contentContainer; |
|||
|
|||
var styleSheet = AssetDatabase.LoadAssetAtPath<StyleSheet>(k_Uss); |
|||
if (styleSheet != null) |
|||
{ |
|||
containerUI.styleSheets.Add(styleSheet); |
|||
} |
|||
else |
|||
{ |
|||
throw new Exception("Asset not found: " + k_Uss); |
|||
} |
|||
|
|||
m_WaitingTextElement = containerUI.Q<TextElement>(className: "auth-progress"); |
|||
m_ErrorTextElement = containerUI.Q<TextElement>(className: "auth-error"); |
|||
|
|||
m_RefreshButton = containerUI.Q<Button>("id-provider-refresh"); |
|||
m_RefreshButton.clicked += RefreshIdProviders; |
|||
|
|||
m_AddButton = containerUI.Q<Button>("id-provider-add"); |
|||
m_AddButton.SetEnabled(false); |
|||
m_AddButton.clicked += AddIdProvider; |
|||
|
|||
m_IdProviderListContainer = containerUI.Q<VisualElement>(className: "auth-id-provider-list"); |
|||
|
|||
m_AddIdProviderContainer = containerUI.Q<VisualElement>("id-provider-type"); |
|||
|
|||
Add(containerUI); |
|||
} |
|||
else |
|||
{ |
|||
throw new Exception("Asset not found: " + k_Uxml); |
|||
} |
|||
} |
|||
|
|||
public void RefreshIdProviders() |
|||
{ |
|||
ShowWaiting(); |
|||
if (m_IdDomainId == null) |
|||
{ |
|||
GetIdDomain(); |
|||
} |
|||
else |
|||
{ |
|||
ListIdProviders(); |
|||
} |
|||
} |
|||
|
|||
void GetIdDomain() |
|||
{ |
|||
var asyncOp = m_AdminClient.GetIDDomain(); |
|||
asyncOp.Completed += OnGetIdDomainCompleted; |
|||
} |
|||
|
|||
void OnGetIdDomainCompleted(IAsyncOperation<string> asyncOp) |
|||
{ |
|||
if (asyncOp.Exception != null) |
|||
{ |
|||
OnError(asyncOp.Exception); |
|||
return; |
|||
} |
|||
|
|||
m_IdDomainId = asyncOp.Result; |
|||
ListIdProviders(); |
|||
} |
|||
|
|||
void ListIdProviders() |
|||
{ |
|||
var asyncOp = m_AdminClient.ListIdProviders(m_IdDomainId); |
|||
asyncOp.Completed += OnListIdProvidersCompleted; |
|||
} |
|||
|
|||
void OnListIdProvidersCompleted(IAsyncOperation<ListIdProviderResponse> asyncOp) |
|||
{ |
|||
if (asyncOp.Exception != null) |
|||
{ |
|||
OnError(asyncOp.Exception); |
|||
return; |
|||
} |
|||
m_IdProviderListContainer.Clear(); |
|||
|
|||
if (asyncOp.Result?.Results != null) |
|||
{ |
|||
foreach (var provider in asyncOp.Result.Results) |
|||
{ |
|||
CreateIdProviderElement(provider); |
|||
} |
|||
} |
|||
|
|||
UpdateAddIdproviderList(); |
|||
HideWaiting(); |
|||
} |
|||
|
|||
void UpdateAddIdproviderList() |
|||
{ |
|||
var unusedIdProviders = new List<string>(IdProviderType.All); |
|||
|
|||
foreach (var child in m_IdProviderListContainer.Children()) |
|||
{ |
|||
if (!(child is IdProviderElement)) |
|||
{ |
|||
continue; |
|||
} |
|||
|
|||
var idProviderElement = (IdProviderElement)child; |
|||
unusedIdProviders.Remove(idProviderElement.SavedValue.Type); |
|||
} |
|||
unusedIdProviders.Sort(); |
|||
|
|||
m_AddIdProviderContainer.Clear(); |
|||
m_AddIdProviderTypeChoices = unusedIdProviders; |
|||
if (unusedIdProviders.Count == 0) |
|||
{ |
|||
m_AddButton.SetEnabled(false); |
|||
} |
|||
else |
|||
{ |
|||
if (unusedIdProviders.Count > 0) |
|||
{ |
|||
m_AddIdProviderType = new PopupField<string>(null, unusedIdProviders, 0); |
|||
m_AddIdProviderContainer.Add(m_AddIdProviderType); |
|||
} |
|||
m_AddButton.SetEnabled(true); |
|||
} |
|||
} |
|||
|
|||
void AddIdProvider() |
|||
{ |
|||
var idProvider = new IdProviderResponse |
|||
{ |
|||
New = true, |
|||
Type = m_AddIdProviderType.value |
|||
}; |
|||
|
|||
CreateIdProviderElement(idProvider); |
|||
} |
|||
|
|||
void OnError(Exception error) |
|||
{ |
|||
error = AuthenticationSettingsHelper.ExtractException(error); |
|||
|
|||
m_ErrorTextElement.style.display = DisplayStyle.Flex; |
|||
m_ErrorTextElement.text = AuthenticationSettingsHelper.ExceptionToString(error); |
|||
Debug.LogError(error); |
|||
HideWaiting(); |
|||
} |
|||
|
|||
void CreateIdProviderElement(IdProviderResponse idProvider) |
|||
{ |
|||
var options = IdProviderOptions.GetOptions(idProvider.Type); |
|||
if (options == null) |
|||
{ |
|||
// the SDK doesn't support the ID provider type yet. Skip.
|
|||
return; |
|||
} |
|||
|
|||
var idProviderElement = new IdProviderElement(m_IdDomainId, m_AdminClient, idProvider, options, m_SkipConfirmation); |
|||
m_IdProviderListContainer.Add(idProviderElement); |
|||
idProviderElement.Waiting += OnIdProviderWaiting; |
|||
idProviderElement.Deleted += OnIdProviderDeleted; |
|||
idProviderElement.Error += OnIdProviderError; |
|||
|
|||
m_IdProviderListContainer.Add(idProviderElement); |
|||
UpdateAddIdproviderList(); |
|||
} |
|||
|
|||
void OnIdProviderWaiting(IdProviderElement sender, bool waiting) |
|||
{ |
|||
if (waiting) |
|||
{ |
|||
ShowWaiting(); |
|||
} |
|||
else |
|||
{ |
|||
HideWaiting(); |
|||
} |
|||
} |
|||
|
|||
void OnIdProviderDeleted(IdProviderElement sender) |
|||
{ |
|||
m_IdProviderListContainer.Remove(sender); |
|||
UpdateAddIdproviderList(); |
|||
} |
|||
|
|||
void OnIdProviderError(IdProviderElement sender, Exception error) |
|||
{ |
|||
OnError(error); |
|||
} |
|||
|
|||
void ShowWaiting() |
|||
{ |
|||
// clear previous error when a new async action is triggered.
|
|||
m_ErrorTextElement.style.display = DisplayStyle.None; |
|||
m_ErrorTextElement.text = string.Empty; |
|||
|
|||
m_WaitingTextElement.style.display = DisplayStyle.Flex; |
|||
SetEnabled(false); |
|||
|
|||
Waiting?.Invoke(this, true); |
|||
} |
|||
|
|||
void HideWaiting() |
|||
{ |
|||
m_WaitingTextElement.style.display = DisplayStyle.None; |
|||
SetEnabled(true); |
|||
Waiting?.Invoke(this, false); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 1f130c428a4b4feb9d46ecee3206cc34 |
|||
timeCreated: 1620752364 |
|
|||
using System; |
|||
|
|||
namespace Unity.Services.Authentication.Editor |
|||
{ |
|||
static class AuthenticationSettingsHelper |
|||
{ |
|||
internal static Exception ExtractException(Exception exception) |
|||
{ |
|||
var aggregatedException = exception as AggregateException; |
|||
if (aggregatedException == null) |
|||
{ |
|||
return exception; |
|||
} |
|||
|
|||
if (aggregatedException.InnerExceptions.Count > 1) |
|||
{ |
|||
// There are multiple exceptions aggregated, don't try to extract exception.
|
|||
return exception; |
|||
} |
|||
|
|||
// It returns the first exception.
|
|||
return aggregatedException.InnerException; |
|||
} |
|||
|
|||
internal static string ExceptionToString(Exception exception) |
|||
{ |
|||
var errorMessage = "[ERROR] "; |
|||
var currentError = exception; |
|||
var firstError = true; |
|||
while (currentError != null) |
|||
{ |
|||
if (!firstError) |
|||
{ |
|||
errorMessage += "\n---> "; |
|||
} |
|||
else |
|||
{ |
|||
firstError = false; |
|||
} |
|||
errorMessage += currentError.Message; |
|||
currentError = currentError.InnerException; |
|||
} |
|||
|
|||
return errorMessage; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 7caccdcd0f744a8d911a745661de6c5c |
|||
timeCreated: 1621631992 |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.Services.Core.Editor; |
|||
using UnityEditor; |
|||
using UnityEngine; |
|||
using UnityEngine.UIElements; |
|||
|
|||
namespace Unity.Services.Authentication.Editor |
|||
{ |
|||
class AuthenticationSettingsProvider : EditorGameServiceSettingsProvider |
|||
{ |
|||
const string k_Title = "Authentication"; |
|||
|
|||
AuthenticationSettingsProvider(SettingsScope scopes, IEnumerable<string> keywords = null) |
|||
: base(GenerateProjectSettingsPath(k_Title), scopes, keywords) {} |
|||
|
|||
/// <summary>
|
|||
/// Accessor for the operate service
|
|||
/// Used to toggle and get dashboard access
|
|||
/// </summary>
|
|||
protected override IEditorGameService EditorGameService => EditorGameServiceRegistry.Instance.GetEditorGameService<AuthenticationIdentifier>(); |
|||
|
|||
/// <summary>
|
|||
/// Title shown in the header for the project settings
|
|||
/// </summary>
|
|||
protected override string Title => k_Title; |
|||
|
|||
/// <summary>
|
|||
/// Description show in the header for the project settings
|
|||
/// </summary>
|
|||
protected override string Description => "This package provides a system for working with the Unity User Authentication Service (UAS), including log-in, player ID and access token retrieval, and session persistence."; |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override VisualElement GenerateServiceDetailUI() |
|||
{ |
|||
var settingsElement = new AuthenticationSettingsElement(AuthenticationAdminClientManager.Instance, CloudProjectSettings.projectId); |
|||
settingsElement.RefreshIdProviders(); |
|||
|
|||
return settingsElement; |
|||
} |
|||
|
|||
/// <inheritdoc/>
|
|||
protected override VisualElement GenerateUnsupportedDetailUI() |
|||
{ |
|||
return GenerateServiceDetailUI(); |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Method which adds your settings provider to ProjectSettings
|
|||
/// </summary>
|
|||
/// <returns>A <see cref="AuthenticationSettingsProvider"/>.</returns>
|
|||
[SettingsProvider] |
|||
public static SettingsProvider CreateSettingsProvider() |
|||
{ |
|||
return new AuthenticationSettingsProvider(SettingsScope.Project); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 78b5efd28d743406b8682bcb71c787a3 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |